【发布时间】:2016-10-24 08:24:44
【问题描述】:
在iPad上测试时,我可以成功调用UILabel中UILongPressGestureRecognizer附加的方法。
在我为企业部署归档应用程序后,UILongPressGestureRecognizer 不再工作。
除了手动勾选User Interaction Enabled:之外,我已经添加了以下代码
在 .h 文件中:
@interface BGMSetMenuViewController : UIViewController <UIGestureRecognizerDelegate>
在 .m 文件中:
- (void)viewDidLoad
{
[super viewDidLoad];
itemPriceLabel.userInteractionEnabled = YES;
itemNameLabel.userInteractionEnabled = YES;
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressSetMenuPrice:)];
longPress.delegate = self;
[itemPriceLabel addGestureRecognizer:longPress];
}
#pragma mark - UILongPressGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (void)longPressSetMenuPrice:(UILongPressGestureRecognizer*)gesture
{
if (gesture.state == UIGestureRecognizerStateEnded) {
BGMPasscodeViewController *passcodeVC = [[BGMPasscodeViewController alloc] initWithNibName:@"BGMPasscodeViewController" bundle:nil];
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
[passcodeVC setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self presentViewController:passcodeVC animated:YES completion:nil];
}
}
这里有没有相同经历的人?
请注意,这适用于 Xcode 7 和 iOS 9。
现在,我正在使用 Xcode 8 并在 iOS 10.0.2 中进行测试,但它不再工作了。
【问题讨论】:
-
发布一些带有问题的UILongPressGestureRecognizer的代码。
-
@JamshedAlam,我已经添加了一些代码和解释。
-
你设置 longPress.delegate = self 了吗?
-
@user3182143,是的,我也有它,我也有 UIGestureRecognizerDelegate。
-
没有看到其他代码,无法给出解决方案。
标签: ios objective-c xcode8 uilongpressgesturerecogni