OGeek|极客世界-中国程序员成长平台

标题: iphone - 向几个 UIView 添加一个手势识别器 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:11
标题: iphone - 向几个 UIView 添加一个手势识别器

所以我有以下代码:

UITapGestureRecognizer *showNewsStoryTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self actionselector(showNewsStory];
[self.storyImageView_ addGestureRecognizer:showNewsStoryTapGestureRecognizer];
[self.storyTitleLabel_ addGestureRecognizer:showNewsStoryTapGestureRecognizer];
[self.storyImageFailedLabel_ addGestureRecognizer:showNewsStoryTapGestureRecognizer];
[self.storyImageFailedTextView_ addGestureRecognizer:showNewsStoryTapGestureRecognizer];
[showNewsStoryTapGestureRecognizer release];

似乎这只适用于一个 UIView,它是最后一个添加的。换句话说,一个 UITapGestureRecognizer 和它的 View 是一对一的关系。这个对吗?我该如何解决?我是否必须为每个单独的 UITapGestureRecog 创建一个?



Best Answer-推荐答案


是的,一个UIView 只能有一个UITapRecogniser。您必须为不同的 View 采用不同的识别器,尽管它们的操作可以相同。
另见 this链接。

关于iphone - 向几个 UIView 添加一个手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11554763/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4