0
我遇到了需要将视图重新定位到预定义位置的问题。计算定位点的旋转角度
所有视图都有UIPanGestureRecognizer
和UIRotationGestureRecognizer
,并在控制器视图中定位/旋转。在某个事件后,视图应该以新的旋转角度移动到新的位置。
一切工作正常,但只要其中一个手势识别器是活动的,因此anchorPoint
改变了重新定位/旋转失败。
这里是我尝试使用anchorPoint
中的转换的方法。
- (CGPoint)centerPointWithInVisibleAreaForPoint:(CGPoint)point
{
CGPoint anchorP = self.layer.anchorPoint;
anchorP.x -= 0.5;
anchorP.y -= 0.5;
CGRect rect = self.bounds;
CGFloat widthDelta = CGRectGetWidth(self.bounds) * anchorP.x;
CGFloat heightDelta = CGRectGetHeight(self.bounds) * anchorP.y;
CGPoint newCenter = CGPointMake(point.x + widthDelta, point.y + heightDelta);
return newCenter;
}
控制器要求校正的中心点并设置视图的中心值。之后,使用CGAffineTransformConcat(view.transform, CGAffineTransformMakeRotation(differenceAngle))
设置旋转变换。
我认为这个问题是由以下事实引起的:预定义的目标角度是基于围绕中心的旋转,当围绕不同的anchorPoint
旋转时明显不同,但我不知道如何补偿这一点。