[英]UILongPressGestureRecognizer on UIButton not working
我有一个在ViewDidLoad中创建的longpress手势识别器,然后将其附加到这样的按钮上,该按钮在情节提要中创建并链接到我的课程。
UILongPressGestureRecognizer *hold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(secretChange:)];
hold.minimumPressDuration = 5.0;
hold.delegate = self;
[_button addGestureRecognizer:hold];
该类符合GestureRecognizer协议,在这里有我的选择器
- (void)secretChange:(UILongPressGestureRecognizer *)sender {
// Some stuff
NSLog(@"Secret");
}
没有调用选择器,我也不知道为什么,这似乎是每个人在互联网上给出的代码,我试图删除最小持续时间,以确保我没有不小心将其设置得很长
更新:我实际上是将此手势识别器添加到这样的多个按钮中
[_button1 addGestureRecognizer:hold];
[_button2 addGestureRecognizer:hold];
[_button3 addGestureRecognizer:hold];
发生的情况是手势识别器仅应用于我将其添加到的最后一个按钮。 如何将手势识别器添加到所有按钮? 我需要为每个按钮制作一个新的按钮吗?
您应该具有UILongPressGestureRecognizer
三个实例。
在将手势识别器添加到新视图之前, addGestureRecognizer
方法将从其附加到的视图中删除手势识别器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.