UIControl,一个交互类
UIImageView无自带的监听事件,可用UIControl来帮助实现监听
UIImageView的交互属性一定要手动打开,默认是关闭的
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"01"]];
//交互属性打开
imageView.userInteractionEnabled = YES;
[imageView setBounds:CGRectMake(0, 0, 40, 40)];
[imageView setCenter:CGPointMake(160, 240)];
[self.view addSubview:imageView];
UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[control addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
//将control添加到imageView上
[imageView addSubview:control];
UIGestureRecognizer,手势控制抽象类
UITapGestureRecognizer:点击手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];
//点击的次数
tap.numberOfTapsRequired = 2;
//手指数
tap.numberOfTouchesRequired = 2;
//视图控件
//对视图添加点击手势
[self.view addGestureRecognizer:tap];
UILongPressGestureRecognizer:长按手势
UILongPressGestureRecognizer *lon = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];
//最短时间
lon.minimumPressDuration = 3;
//响应之前可移动的距离
lon.allowableMovement = 240;
[self.view addGestureRecognizer:lon];
UIRotationGestureRecognizer:旋转手势
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];
[self.view addGestureRecognizer:rotation];
属性:
rotation 旋转的角度(弧度)
velocity 角速度
UISwipeGestureRecognizer:滑动手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipe];
属性:</