Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for iPhone X safe area #618

Open
calbot opened this issue Sep 29, 2017 · 1 comment
Open

Support for iPhone X safe area #618

calbot opened this issue Sep 29, 2017 · 1 comment

Comments

@calbot
Copy link

calbot commented Sep 29, 2017

Bottom toolbar gets cut off on iPhone X so here's what I did to fix it.
Updated MWPhotoBrowser.m


- (CGRect)frameForToolbarAtOrientation:(UIInterfaceOrientation)orientation {
    CGFloat height = 44;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
        UIInterfaceOrientationIsLandscape(orientation)) height = 32;
    CGFloat adjust = 0;
    if (@available(iOS 11.0, *)) {
        //Account for possible notch
        UIEdgeInsets safeArea = [[UIApplication sharedApplication] keyWindow].safeAreaInsets;
        adjust = safeArea.bottom;
    }
	return CGRectIntegral(CGRectMake(0, self.view.bounds.size.height - height - adjust, self.view.bounds.size.width, height));
}
pagrit added a commit to willhaben/MWPhotoBrowser that referenced this issue Nov 15, 2017
@foolsparadise
Copy link

如果不好使,另加一个其它方法
If unuseful, you can check this
这一块代码,在commit 66ddd73-on Apr 22, 2016基础上添加的,使用工程中的Library photos and videos一块,UI在iPhoneX上我这边试了下是OK了,其它建议类推。希望能帮到你。
Library photos and videos UI in this project , checked Run OK in iPhoneX , code based on commit 66ddd73-on Apr 22, 2016 , maybe help you

diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m
index 0de7faa..80dcf8d 100644
--- a/Pod/Classes/MWPhotoBrowser.m
+++ b/Pod/Classes/MWPhotoBrowser.m
@@ -15,6 +15,12 @@
 
 #define PADDING                  10
 
+#define IOS11_OR_LATER_SPACE(par) ({ float space = 0.0; if ([[UIDevice currentDevice] systemVersion].floatValue>=11) { space = par; } (space); })
+#define JF_KEY_WINDOW [UIApplication sharedApplication].keyWindow
+#define JF_TOP_SPACE IOS11_OR_LATER_SPACE(JF_KEY_WINDOW.safeAreaInsets.top)
+#define JF_TOP_ACTIVE_SPACE IOS11_OR_LATER_SPACE(MAX(0, JF_KEY_WINDOW.safeAreaInsets.top-20))
+#define JF_BOTTOM_SPACE IOS11_OR_LATER_SPACE(JF_KEY_WINDOW.safeAreaInsets.bottom)
+
 static void * MWVideoPlayerObservation = &MWVideoPlayerObservation;
 
 @implementation MWPhotoBrowser
@@ -161,6 +167,9 @@ static void * MWVideoPlayerObservation = &MWVideoPlayerObservation;
        
     // Toolbar
     _toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:self.interfaceOrientation]];
+    CGRect frame = _toolbar.frame;
+    frame.origin.y = self.view.bounds.size.height - frame.size.height - JF_BOTTOM_SPACE;
+    _toolbar.frame = frame;
     _toolbar.tintColor = [UIColor whiteColor];
     _toolbar.barTintColor = nil;
     [_toolbar setBackgroundImage:nil forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
@@ -283,6 +292,9 @@ static void * MWVideoPlayerObservation = &MWVideoPlayerObservation;
         [_toolbar removeFromSuperview];
     } else {
         [self.view addSubview:_toolbar];
+        CGRect frame = _toolbar.frame;
+        frame.origin.y = self.view.bounds.size.height - frame.size.height - JF_BOTTOM_SPACE;
+        _toolbar.frame = frame;
     }
     
     // Update nav
@@ -495,7 +507,9 @@ static void * MWVideoPlayerObservation = &MWVideoPlayerObservation;
        
        // Toolbar
        _toolbar.frame = [self frameForToolbarAtOrientation:self.interfaceOrientation];
-    
+    CGRect frame = _toolbar.frame;
+    frame.origin.y = self.view.bounds.size.height - frame.size.height - JF_BOTTOM_SPACE;
+    _toolbar.frame = frame;
        // Remember index
        NSUInteger indexPriorToLayout = _currentPageIndex;
        
@@ -1438,7 +1452,9 @@ static void * MWVideoPlayerObservation = &MWVideoPlayerObservation;
         
         // Toolbar
         _toolbar.frame = CGRectOffset([self frameForToolbarAtOrientation:self.interfaceOrientation], 0, animatonOffset);
-        
+        CGRect frame = _toolbar.frame;
+        frame.origin.y = self.view.bounds.size.height - frame.size.height - JF_BOTTOM_SPACE;
+        _toolbar.frame = frame;
         // Captions
         for (MWZoomingScrollView *page in _visiblePages) {
             if (page.captionView) {
@@ -1461,6 +1477,9 @@ static void * MWVideoPlayerObservation = &MWVideoPlayerObservation;
         // Toolbar
         _toolbar.frame = [self frameForToolbarAtOrientation:self.interfaceOrientation];
         if (hidden) _toolbar.frame = CGRectOffset(_toolbar.frame, 0, animatonOffset);
+        CGRect frame = _toolbar.frame;
+        frame.origin.y = self.view.bounds.size.height - frame.size.height - JF_BOTTOM_SPACE;
+        _toolbar.frame = frame;
         _toolbar.alpha = alpha;
 
         // Captions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants