我想使用平移手势识别器移动视图。
UIPanGestureRecognizer *gesture;
CGPoint touch = [gesture locationInView:view.superview];
view.frame = CGRectMake(touch.x, touch.y, view.frame.size.width, view.frame.size.height);
此外,我想在视图移动时旋转视图。
view.transform = CGAffineTransformMakeRotation(multiplier * M_2_PI);
我有两个基本问题:
有人可以给我一个非常基本的代码示例,说明如何使用 CGAffineTransform 修复这些问题,而不是去阅读本文吗?
答案 0 :(得分:2)
您可以在此处找到代码示例https://github.com/K-Be/ViewMovingTest 主要想法是
这是一些代码:
if (_panRecognizer.state == UIGestureRecognizerStateBegan)
{
_startCenter = _frameView.center;
}
else if (_panRecognizer.state == UIGestureRecognizerStateChanged)
{
CGPoint transition = [_panRecognizer translationInView:self.view];
CGPoint newCenter = CGPointMake(_startCenter.x + transition.x, _startCenter.y + transition.y);
self.frameView.center = newCenter;
}
else
{
}
和
CGAffineTransform transform = self.frameView.transform;
self.frameView.transform = CGAffineTransformIdentity;
self.frameView.frame = CGRectInset(self.view.bounds, CGRectGetWidth(self.view.bounds) / 3.0, CGRectGetHeight(self.view.bounds) / 3.0);
self.frameView.transform = transform;