2016-10-24 46 views
0

在iPad中測試時,我可以成功調用UILabel中UILongPressGestureRecognizer附帶的方法。UILongPressGestureRecognizer無法在歸檔應用程序後工作

在我將Enterprise應用程序存檔歸檔後,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,它不工作了。

+0

後UILongPressGestureRecognizer的一些代碼的問題。 –

+0

@JamshedAlam,我添加了一些代碼和解釋。 –

+0

您是否設置了longPress.delegate = self? – user3182143

回答

0

試試下面的代碼:設置YES標記userIntractionEnabled也是故事板

- (void)viewDidLoad { 
[super viewDidLoad]; 
labelTouch.userInteractionEnabled = YES; 
[self labelLongPressed:labelTouch];} 


- (void)labelLongPressed:(UILabel *)label{ 
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
            initWithTarget:self action:@selector(handleLongPress:)]; 
longPress.minimumPressDuration = 2; //seconds 
longPress.delegate = self; 
[label addGestureRecognizer:longPress];} 

-(void) handleLongPress : (UITapGestureRecognizer *)sender{ 
    UIButton *button = (UIButton *)sender.view; 
    NSLog(@"longpress");} 
相關問題