在 iPad 中测试时,我可以成功调用UILongPressGestureRecognizer
UILabel 中附加的方法。
在我为企业部署归档应用程序后,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 中进行测试,但它不再工作了。