UIresponder:响应者(传达者) 用来响应用户触摸屏幕的某些事件
标签: UILabel
按钮: UIButton
文本框: UITextField
滚动视图: UIScrollView
视图控制器: UIViewController
根视图: RootViewController
分栏控制器: UITabBarController
放图片的视图: UIImageView
联系人通讯录: UITableView
通讯录一行的视图 :UITableViewCell
滑动点点点点: UIPageControl
用户的默认信息: NSUserDefaults
手势分为六大手势:
六大手势全部都继承自UIGestureRecognizer
1、点击UITapGestureRecognizer
2、长按UILongPressGestureRecognizer
3、拖拽UIPanGestureRecognizer
4、捏合UIPinchGestureRecognizer
5、轻扫UISwipeGestureRecognizer
6、旋转UIRotationGestureRecognizer
初始化手势
UITapGestureRecognizer*tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(actionOfTap:)];
设置点击手势的点击次数
tap.numberOfTapsRequired = 2;
设置点击手指的个数
tap.numberOfTouchesRequired = 2;
添加到视图是addGestureRecognizer: 而不是 addsubview:
[xx视图 addGestureRecognizer:xx手势];
minimumPressDuration设置长按的时间(多长时间才会调用长按触发事件)
1.手指开始触摸屏幕调用方法:- (void)touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event;
2.手指离开屏幕调用方法:- (void)touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event;
3.手指因外部事件取消触摸调用方法:- (void)touchesCancelled:(nullable NSSet *)touches withEvent:(nullable UIEvent *)event;
程序走的流程:用户点击屏幕触发->所有视图都继承UIResponder->UITuchBegin moved end
UITuchBegin moved end
获得点击视图的位置
CGPoint point = [xx手势locationInView:xx视图];
如果发现手势不调用.检查一下看是不是设置了背景颜色
网友评论