例子一
给图片添加事件
//图像添加点击事件(手势方法)
self.headImageView.userInteractionEnabled = YES;
UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView:)];
PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
PrivateLetterTap.delegate= self;
self.headImageView.contentMode = UIViewContentModeScaleToFill;
[self.headImageView addGestureRecognizer:PrivateLetterTap];
方法
#pragma mark ---"头像"点击触发的方法,完成跳转
- (void)tapAvatarView: (UITapGestureRecognizer *)gesture
{
if (![PublicFunc isUserLogined]) {
[PublicFunc requireLogin:^(BOOL success) {
}];
} else {
MyCardViewController *viewController = [[MyCardViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
}
}
例子二
给图片添加手势
footImageView.userInteractionEnabled = YES; UITapGestureRecognizer*singleTap33=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toCityByClicked:)];
singleTap33.numberOfTouchesRequired = 1; //手指数
singleTap33.numberOfTapsRequired = 1; //tap次数
singleTap33.delegate= self;
footImageView.contentMode = UIViewContentModeScaleToFill;
[footImageView addGestureRecognizer:singleTap33];
方法
//城市图片点击事件方法(跳转到城市体验列表)
-(void)toCityByClicked:(id)sender{
UITapGestureRecognizer *tap = (UITapGestureRecognizer*)sender;
UIView *views = (UIView*) tap.view;
int tagClicked = (int)views.tag;
//城市名点击,传下个界面,显示对应城市体验列表
ActivityViewController * activityVC = [[ActivityViewController alloc]init];
DZY_HomePageItemModel * cityItemModel = itemChengshiArrs[0];
NSArray * cityArr = [NSArray arrayWithArray:cityItemModel.itemsArray];
NSDictionary * cityDic = cityArr[tagClicked];
DZY_CommonModel * cityFootModel = [[DZY_CommonModel alloc]init];
[cityFootModel setValuesForKeysWithDictionary:cityDic];
activityVC.searchArea=cityFootModel.entityName;
[self.navigationController pushViewController:activityVC animated:YES];
}