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;
}
问题是当popover呈现时,我仍然能够点击标题标签和弹出窗口不会解雇。另外,如果我点击状态栏popover不会解雇。这个问题的原因是什么?