LGAlertView icon indicating copy to clipboard operation
LGAlertView copied to clipboard

LGAlertViewStyleActionSheet misplaced on iPhone X

Open mickeyl opened this issue 8 years ago • 5 comments

On iPhone X, LGAlertViewStyleActionSheet overlays the home indicator bar, which violates the Apple HIG.

mickeyl avatar Sep 15 '17 15:09 mickeyl

you can set alert.cancelButtonOffsetY=20;

heroims avatar Sep 21 '17 07:09 heroims

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.

mickeyl avatar Sep 21 '17 08:09 mickeyl

safe area not support yet

Mr-yuwei avatar Nov 05 '18 02:11 Mr-yuwei

@mickeyl are you resolved this issue??? in my case alert.cancelButtonOffsetY=20; is not working..

techinpark2 avatar Dec 13 '18 01:12 techinpark2

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;

mickeyl avatar Dec 15 '18 20:12 mickeyl