Open mickeyl opened 7 years ago
you can set alert.cancelButtonOffsetY=20;
Thanks, @heroims. While this is a fine workaround for iPhone X, to make it work everywhere, I'd rather suggest consulting the safe area (or bottom layout margin to make it compatible with iOS < 11) instead.
safe area not support yet
@mickeyl are you resolved this issue??? in my case alert.cancelButtonOffsetY=20; is not working..
I'm not too proud of this patch, but it's a quick fix. The layout code of LGAlertView is very convoluted, almost unmaintainable in my humble opinion. The major issue is that layoutValidateWithSize
only respects the size, thinking it can fill the whole container area. A proper fix would a) need to rewrite this to handle insets on all possible sides, and b) adjust the LGAlertViewController
to handle viewSafeAreaInsetsDidChange
, because getting the safe area insets from the previous key window is hacky as well.
Anyways, here's the quick workaround in case it's helpful:
diff --git a/LGAlertView/LGAlertView.m b/LGAlertView/LGAlertView.m
index 0d78d95..d644fb9 100644
--- a/LGAlertView/LGAlertView.m
+++ b/LGAlertView/LGAlertView.m
@@ -121,6 +121,7 @@ @interface LGAlertView () <UITableViewDataSource, UITableViewDelegate, UITextFie
@property (assign, nonatomic) LGAlertViewType type;
@property (assign, nonatomic) CGFloat keyboardHeight;
+@property (assign, nonatomic) CGFloat safeAreaBottomInset;
@property (strong, nonatomic) NSMutableDictionary *buttonsPropertiesDictionary;
@property (strong, nonatomic) NSMutableArray *buttonsEnabledArray;
@@ -1541,6 +1542,10 @@ - (void)showAnimated:(BOOL)animated hidden:(BOOL)hidden completionHandler:(LGAle
self.window.windowLevel = UIWindowLevelStatusBar + (self.windowLevel == LGAlertViewWindowLevelAboveStatusBar ? 1 : -1);
self.view.userInteractionEnabled = NO;
+ if ( @available( iOS 11.0, * ) )
+ {
+ self.safeAreaBottomInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
+ }
CGSize size = self.viewController.view.bounds.size;
@@ -2797,7 +2802,7 @@ - (void)layoutValidateWithSize:(CGSize)size {
}
else
{
- CGFloat bottomShift = self.offsetVertical;
+ CGFloat bottomShift = self.offsetVertical + self.safeAreaBottomInset / 2.0;
if (kLGAlertViewIsCancelButtonSeparate(self) && self.cancelButton) {
bottomShift += self.buttonsHeight+self.cancelButtonOffsetY;
On iPhone X, LGAlertViewStyleActionSheet overlays the home indicator bar, which violates the Apple HIG.