UIView的手势处理能够响应点击事件。(此处使用 UIImageView 做为示例)ide
1. self.allScreenImg.userInteractionEnabled = YES;//UIImageView默认不响应手势,须要开启userInteractionEnabledspa
//处理单击事件.net
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAllScreen:)];orm
[self.allScreenImg addGestureRecognizer:singleTap];事件
2. 添加处理的方法get
- (void) clickAllScreen:(UITapGestureRecognizer *) recognizer {it
AllScreenViewController* recordViewController = [[AllScreenViewController alloc] initWithStoryboard];io
[self.navigationController pushViewController:recordViewController animated:YES];event
}class
以上操做便可以响应了UIImageView的点击事件了。
方法二:
为UIImageView设置tag,直接处理手势 以处理单击事件:
p_w_picpathView.setTag = 333;
-(void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event {
UIImageView* img = (UIImageView *) [self.view viewWithTag: 333];
if (img) {
// TODO some thing
}
}