From ae5a3f49686116bbe7ee56c92f7485e21c431cb1 Mon Sep 17 00:00:00 2001 From: Matthew Suggit Date: Mon, 30 Nov 2015 15:23:31 +0000 Subject: [PATCH] Add anchor for popover for iPad On iPad the alert is a UIPopoverPresentationController so you have to provide a source view to anchor. It works as before on iPhone. --- AlertController/Source/AlertController.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/AlertController/Source/AlertController.m b/AlertController/Source/AlertController.m index 21dcd48..32b284f 100644 --- a/AlertController/Source/AlertController.m +++ b/AlertController/Source/AlertController.m @@ -11,6 +11,7 @@ @interface AlertController () @property (nonatomic, strong) UIWindow *alertWindow; +@property (nonatomic, strong) UIButton *popoverAnchorButton; @end @@ -25,6 +26,14 @@ - (UIWindow *)alertWindow { return _alertWindow; } +- (UIButton *)popoverAnchorButton { + if (_popoverAnchorButton == nil) { + _popoverAnchorButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [self.alertWindow addSubview:_popoverAnchorButton]; + } + return _popoverAnchorButton; +} + - (void)show { [self show:YES completion:nil]; } @@ -34,6 +43,9 @@ - (void)show:(BOOL)animated { } - (void)show:(BOOL)animated completion:(void (^)(void))completion { + self.popoverPresentationController.sourceView = self.popoverAnchorButton; + self.popoverPresentationController.sourceRect = self.popoverAnchorButton.bounds; + [self.alertWindow makeKeyAndVisible]; [self.alertWindow.rootViewController presentViewController:self animated:animated completion:completion];