gpt4 book ai didi

ios - UIPopoverPresentationController 不会禁用标题 View 上的点击手势

转载 作者:行者123 更新时间:2023-12-01 19:50:39 27 4
gpt4 key购买 nike

我有带有导航栏的 View Controller ,其中包含处理点击手势的标题 View 。还有一个rightBarButtonItem其中显示 UIAlertController在 iPad 上作为弹出框。下面的示例代码:

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

最佳答案

根据一个答案:

UIPopoverController does not dismiss when clicking on the NavigationBar

UIPopoverController seems to add the navigation bar to its passthroughViews array when it is presented.



解决办法是:
[self presentViewController:controller animated:YES completion:^{
controller.popoverPresentationController.passthroughViews = nil;
}];

关于ios - UIPopoverPresentationController 不会禁用标题 View 上的点击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46212486/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com