美文网首页
iPhone X机型判断,iPhone X Model

iPhone X机型判断,iPhone X Model

作者: 天狐博客 | 来源:发表于2017-09-14 11:41 被阅读0次

    目前还不知道iPhone X的Devive Model,可以拿分辨率来判断。


    #define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

    适配iPhone X如火如荼啊。天狐发现很多地方需要代码判断iPhone X机型。

    举个例子。

    原生的tabbar高度为49pt.当iPhone X时候自动变为了83pt,自动拉伸了34pt。

    有很多反人类但是必须得做的需求是,需要把tabbar
    高度改为非原生值,比如改成死值55.

    - (void)viewWillLayoutSubviews{

    CGRect tabFrame = self.tabBar.frame;

    tabFrame.size.height = 55;

    tabFrame.origin.y = self.view.frame.size.height - 55;

    self.tabBar.frame = tabFrame;

    }

    这时候iPhonex 中就有问题了。

    所以要换个方法,不要写死值。要么加变化量。要么单独判断下。


    - (void)viewWillLayoutSubviews{

    CGRect tabFrame = self.tabBar.frame;

    CGFloat height  = tabFrame.size.height;

    if(RD_iPhoneX){

    height += 0;

    }else{

    height += 6;

    }

    tabFrame.size.height = height;

    tabFrame.origin.y = self.view.frame.size.height - height;

    self.tabBar.frame = tabFrame;

    }


    相关文章

      网友评论

          本文标题:iPhone X机型判断,iPhone X Model

          本文链接:https://www.haomeiwen.com/subject/lctdsxtx.html