ios开发怎么设置uiimageview点击不可用
答案:2 悬赏:70 手机版
解决时间 2021-11-19 09:10
- 提问者网友:风月客
- 2021-11-19 04:49
ios开发怎么设置uiimageview点击不可用
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-11-19 04:55
千锋扣丁学堂iOS开发为您解答:
UIImageView并不像UIButton一样,点点鼠标就可以关联点击事件,也不像Android里有onClickListener,这里需要借助于UITapGestureRecognizer类。从类名上就可以看出,这个类就是用于处理tap(单击)事件的。
bbc和voaspecial是UIImageView对象
1
2
3
4
[bbc setUserInteractionEnabled:YES];
[voaspecial setUserInteractionEnabled:YES];
[bbc addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCategory:)]];
[voaspecial addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCategory:)]];
经测试,多个UIImageView不能共用一个UITapGestureRecognizer对象,之前调用的会没效果。
根据点击的view判断来自谁的点击。
-(void)clickCategory:(UITapGestureRecognizer *)gestureRecognizer
{
NSLog(@"click");
NSLog(@"%hhd",[gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]]);
UIView *viewClicked=[gestureRecognizer view];
if (viewClicked==bbc) {
NSLog(@"bbc");
}else if(viewClicked==voaspecial)
{
NSLog(@"voaspecial");
}
}
UIImageView并不像UIButton一样,点点鼠标就可以关联点击事件,也不像Android里有onClickListener,这里需要借助于UITapGestureRecognizer类。从类名上就可以看出,这个类就是用于处理tap(单击)事件的。
bbc和voaspecial是UIImageView对象
1
2
3
4
[bbc setUserInteractionEnabled:YES];
[voaspecial setUserInteractionEnabled:YES];
[bbc addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCategory:)]];
[voaspecial addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCategory:)]];
经测试,多个UIImageView不能共用一个UITapGestureRecognizer对象,之前调用的会没效果。
根据点击的view判断来自谁的点击。
-(void)clickCategory:(UITapGestureRecognizer *)gestureRecognizer
{
NSLog(@"click");
NSLog(@"%hhd",[gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]]);
UIView *viewClicked=[gestureRecognizer view];
if (viewClicked==bbc) {
NSLog(@"bbc");
}else if(viewClicked==voaspecial)
{
NSLog(@"voaspecial");
}
}
全部回答
- 1楼网友:封刀令
- 2021-11-19 05:55
userInteractionEnabled = NO
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯