1

タップジェスチャーを処理するタイトルビューを含むナビゲーションバーを備えたビューコントローラーがあります。また、rightBarButtonItemは、ポップオーバーとしてiPadにUIAlertControllerを表示しています。以下のサンプルコード:UIPopoverPresentationControllerはタイトルビューでタップジェスチャーを無効にしません

- (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; 
} 

問題は、ポップオーバーが提示されています。私はまだタイトルラベルをタップすることができ、ポップオーバーは却下されません。また、ステータスバーのポップオーバーをタップしても却下されません。その問題の原因は何でしょうか?

enter image description here

enter image description here

答えて

0

の答えによると:

UIPopoverController does not dismiss when clicking on the NavigationBar

UIPopoverControllerそれが提示されたときにその passthroughViewsアレイにナビゲーションバーを追加しているようです。

ソリューションを行うことです。

[self presentViewController:controller animated:YES completion:^{ 
    controller.popoverPresentationController.passthroughViews = nil; 
}]; 
関連する問題