标签:
今天讲一下姿势识别器,UIGestureRecognizer这个是抽象类
1、拍击UITapGestureRecognizer (任意次数的拍击)
2、向里或向外捏UIPinchGestureRecognizer (用于缩放)
3、摇动或者拖拽UIPanGestureRecognizer (拖动)
4、擦碰UISwipeGestureRecognizer (以任意方向)
5、旋转UIRotationGestureRecognizer (手指朝相反方向移动)
6、长按UILongPressGestureRecognizer (长按)
基本用法是
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
然后定义它的回调方法handlePan:,每当用户在屏幕对对象进行相应的姿势进行操作的时候,都会触发回调方法
-(void)handlePan:(UIPanGestureRecognizer *) recognizer { CGPoint translatedPoint = [recognizer translationInView:self.superview]; self.center = CGPointMake(previousLocation.x+translatedPoint.x, previousLocation.y+translatedPoint.y); }
回调方法中会有UIPanGestureRecognizer对应的识别器,识别器可以计算出在对应视图中的操作像素,如上面的代码,translationInView就是计算出在父视图中,的平移想像素
并重新设置视图的中心点,previousLocation为点击视图时记录的视图位置点,加上平移的像素,就会得出视图的中心点的偏移量
1 - 姿势识别器UIPanGestureRecognizer
标签:
原文地址:http://www.cnblogs.com/oscar1987121/p/5665278.html