ios - 不同类别的手势识别器?

标签 ios objective-c

我想知道这是否可能。 拥有一个向主视图添加新 imageView 并为其分配手势识别器的类。

所以在我的 View 生成器类中,我有以下内容:

UIImageView *headerPlusIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plusIcon.png"]];
headerPlusIcon.frame = CGRectMake(header.frame.size.width - 2.5*(logoSize - 8), yPosition*1.6, logoSize*0.9, logoSize*0.9);
headerPlusIcon.userInteractionEnabled = YES;

UIGestureRecognizer *headerTapGesture = [[UIGestureRecognizer alloc] initWithTarget:mainView action:@selector(testTapGesture:)];
[headerPlusIcon addGestureRecognizer:headerTapGesture];

点击手势方法是这样的:

-(void)testTapGesture:(UITapGestureRecognizer *)gesture
{
    dispatch_async(dispatch_get_main_queue(), ^{
        mainView.backgroundColor = [UIColor redColor];
    });
}

mainView 是通过构造函数传递给此类的,它只是主视图。

这样调用:

mainViewbuilder = [[MainViewBuilder alloc] initWithBaseView:self.view];
[mainViewbuilder buildHeader];

不幸的是,点击手势方法永远不会被调用...如何正确完成? 谢谢!

最佳答案

试试 UITapGestureRecognizer

Apple Docs on UITapGestureRecognizer

关于ios - 不同类别的手势识别器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27132368/

相关文章:

objective-c - 奇怪的 EXC_Crash (SIGKILL) 错误报告

ios - Shopify iOS SDK - 将 BuyProductVariant 转换为 BuyProduct 的问题

objective-c - iOS 应用程序和持久登录(显然是特定于手机和特定于应用程序的问题)

ios - 在 iOS 7 中管理核心数据线程

objective-c - 在这些平台和情况下切换到 Objective-C 是否可行?

ios - 使用Core Plot对饼图切片进行动画处理

ios - 如何在 Storyboard中更改 View Controller 的标题

ios - NSTimer 启动延迟

objective-c - 从另一个类访问发送者方法

ios - 如何使 UITableView 行随用户修改的内容动态增长