yackle / CLImageEditor

MIT License
2.21k stars 574 forks source link

iPhone X Support #192

Closed Tom-Shen closed 6 years ago

Tom-Shen commented 6 years ago

I am currently updating my app to the newly released iPhone X. CLImageEditor looks mostly fine, except for the bottom bar it is right under the home bar, being obscured. Would be better if the bottom bar can be lifted up on the new device.

cliffjoyce commented 6 years ago

+1

Tom-Shen commented 6 years ago

Found a quick fix. Change initMenuScrollView on _CLImageEditorViewController.m to:

- (void)initMenuScrollView
{
    if(self.menuView==nil){
        UIScrollView *menuScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 80)];
        menuScroll.top = self.view.height - menuScroll.height;

        // Adjust for iPhone X
        CGRect screenBounds = [[UIScreen mainScreen] bounds];
        CGFloat screenScale = [[UIScreen mainScreen] scale];
        if (screenBounds.size.width * screenScale == 1125 && screenBounds.size.height * screenScale == 2436) {
            // iPhone X
            menuScroll.top -= 20;
        }

        menuScroll.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
        menuScroll.showsHorizontalScrollIndicator = NO;
        menuScroll.showsVerticalScrollIndicator = NO;

        [self.view addSubview:menuScroll];
        self.menuView = menuScroll;
    }
    self.menuView.backgroundColor = [CLImageEditorTheme toolbarColor];
}
cliffjoyce commented 6 years ago

Building on the idea from @Tom-Shen, here's a slightly different version that should also handle landscape orientation:

// Adjust for iPhone X
if (@available(iOS 11.0, *)) {
    UIEdgeInsets theInsets = [UIApplication sharedApplication].keyWindow.rootViewController.view.safeAreaInsets;
    menuScroll.top = menuScroll.top - theInsets.bottom;
}
yackle commented 6 years ago

Thanks All, I'll fix it later.

cliffjoyce commented 6 years ago

Thanks for merging this into the latest build. And thanks VERY MUCH for the landscape support!