1

J'ai un contrôleur de vue avec une barre de navigation contenant une vue de titre qui gère le geste du robinet. Il y a aussi un rightBarButtonItem qui montre UIAlertController sur iPad comme popover. Exemple de code ci-dessous:UIPopoverPresentationController ne désactive pas le geste du robinet sur la vue du titre

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.view.backgroundColor = UIColor.whiteColor; 

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; 
    titleLabel.text = @"Popover test"; 
    titleLabel.backgroundColor = UIColor.greenColor; 
    titleLabel.userInteractionEnabled = YES; 
    [titleLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(titleLabelPress)]]; 

    self.navigationItem.titleView = titleLabel; 

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                          target:self 
                          action:@selector(showPopover)]; 
} 

- (void)showPopover { 
    UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil 
                     message:nil 
                   preferredStyle:UIAlertControllerStyleActionSheet]; 
    controller.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItem; 

    [controller addAction:[UIAlertAction actionWithTitle:@"One" style:UIAlertActionStyleDefault handler:nil]]; 
    [controller addAction:[UIAlertAction actionWithTitle:@"Two" style:UIAlertActionStyleDefault handler:nil]]; 

    [self presentViewController:controller animated:YES completion:nil]; 
} 

- (void)titleLabelPress { 
    BOOL isYellow = [((UILabel *)self.navigationItem.titleView).backgroundColor isEqual:UIColor.yellowColor]; 
    ((UILabel *)self.navigationItem.titleView).backgroundColor = isYellow ? UIColor.greenColor : UIColor.yellowColor; 
} 

Le problème est quand je popover présente encore en mesure de taper sur l'étiquette de titre et popover ne rejettera pas. Aussi, si je tape sur la barre d'état popover ne sera pas ignorer. Quelle pourrait être la raison de ces problèmes?

enter image description here

enter image description here

Répondre

0

Selon une réponse à:

UIPopoverController does not dismiss when clicking on the NavigationBar

UIPopoverController semble ajouter la barre de navigation à son tableau passthroughViews quand il est présenté.

La solution est de faire:

[self presentViewController:controller animated:YES completion:^{ 
    controller.popoverPresentationController.passthroughViews = nil; 
}];