【发布时间】:2014-03-23 21:27:46
【问题描述】:
我正在尝试翻译已使用用户触摸旋转和/或缩放的 UIView。我也尝试使用用户输入来翻译它:
- (void)handleObjectMove:(UIPanGestureRecognizer *)recognizer
{
static CGPoint lastPoint;
UIView *moveView = [recognizer view];
CGPoint newCoord = [recognizer locationInView:playArea];
// Check if this is the first touch
if( [recognizer state]==UIGestureRecognizerStateBegan )
{
// Store the initial touch so when we change positions we do not snap
lastPoint = newCoord;
}
// Create the frame offsets to use our finger position in the view.
float dX = newCoord.x;
float dY = newCoord.y;
dX-=lastPoint.x;
dY-=lastPoint.y;
// Figure out the translation based on how we are scaled
CGAffineTransform transform = [moveView transform];
CGFloat xScale = transform.a;
CGFloat yScale = transform.d;
dX/=xScale;
dY/=yScale;
lastPoint = newCoord;
[moveView setTransform:CGAffineTransformTranslate( transform, dX, dY )];
[recognizer setTranslation:CGPointZero inView:playArea];
}
但是当我触摸并移动视图时,它会以各种不同的奇怪方式进行翻译。我可以使用旋转值应用某种公式来正确翻译吗?
【问题讨论】:
-
换句话说,您正在尝试将来自该识别器的翻译与来自另一个手势识别器(例如,UIPinchGestureRecognizer)的旋转和/或缩放结合起来?
-
没错。 UIView 在翻译之前已经被用户输入旋转和/或缩放。所以我需要保持旋转/缩放并翻译它。
标签: ios objective-c rotation translation cgaffinetransform