【发布时间】:2015-03-06 19:53:14
【问题描述】:
我正在开发一个应用程序,该应用程序允许用户使用 UIGestureRecognizers 调整照片大小和旋转照片。我有这段代码,它根据用户应用触摸的位置调整anchorPoint(以使其看起来像是在他们的手指实际位置缩放图像):
- (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
UIView *gestureRecognizerView = gestureRecognizer.view;
CGPoint locationInView = [gestureRecognizer locationInView:gestureRecognizerView];
CGPoint locationInSuperview = [gestureRecognizer locationInView:gestureRecognizerView.superview];
gestureRecognizerView.layer.anchorPoint = CGPointMake(locationInView.x / gestureRecognizerView.bounds.size.width, locationInView.y / gestureRecognizerView.bounds.size.height);
gestureRecognizerView.center = locationInSuperview;
}
稍后,我只想使用以下代码根据中心和边界计算原点:
CGRect transformedBounds = CGRectApplyAffineTransform(view.bounds, view.transform);
CGPoint origin = CGPointMake(view.center.x - (transformedBounds.size.width * view.layer.anchorPoint.x), view.center.y - (transformedBounds.size.height * view.layer.anchorPoint.y));
而且它的输出不正确(我正在与具有讽刺意味的是应该无效但实际上确实具有正确值的帧值进行比较。
总之我想知道,我在这里没有考虑什么? anchorPoint 如何以我无法确定的方式影响中心?
【问题讨论】:
-
点赞this
-
@DavidRönnqvist - 谢谢你的帮助
标签: ios iphone cocoa-touch uiview