Ich habe View-Controller mit Navigationsleiste, die eine Titelansicht enthält, die die Tipp-Geste behandelt. Auch gibt es eine rightBarButtonItem
, die UIAlertController
auf dem iPad als Popover zeigt. Beispiel-Code unten:UIPopoverPresentationController deaktiviert die Antippen-Geste in der Titelansicht nicht
- (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;
}
Das Problem ist, wenn popover präsentiert I auf Titel Etikett klopfen noch in der Lage und popover nicht entlassen. Auch wenn ich auf Statusleiste tippe Popover wird nicht entlassen. Was könnte der Grund für diese Probleme sein?