locationInView:和translationInView:的区别

最近项目中需要有图片裁剪功能,可以自定义的缩放编辑区域,想了好多方法但是都不是很理想,后来找到手势的locationInView 和translationInView这个两个方法,才恍然大悟!

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
    [self.view addGestureRecognizer:pan];
}

- (void)move:(UIPanGestureRecognizer *)pan {
    CGPoint point = [pan locationInView:self.view];
    CGPoint transPoint = [pan translationInView:self.view];
    NSLog(@"%f++++%f\n --- \n%f+++++%f",point.x,point.y,transPoint.x,transPoint.y);
}

2015-07-09 10:50:13.457 Demo[505:80716] 157.500000++++263.500000
 ---
0.000000+++++0.000000

2015-07-09 10:50:13.657 Demo[505:80716] 159.000000++++263.500000
 ---
1.500000+++++0.000000
2015-07-09 10:50:13.690 Demo[505:80716] 159.500000++++263.500000
 ---
2.000000+++++0.000000
2015-07-09 10:50:14.057 Demo[505:80716] 159.500000++++263.000000
 ---
2.000000+++++-0.500000
2015-07-09 10:50:14.073 Demo[505:80716] 159.500000++++263.000000
 ---
2.000000+++++-0.500000


locationInView:获取到的是手指点击屏幕实时的坐标点;

translationInView:获取到的是手指移动后,在相对坐标中的偏移量


你可能感兴趣的:(UIView)