美文网首页
判断机型

判断机型

作者: 无名小卒赫 | 来源:发表于2016-08-10 15:01 被阅读13次

    ```

    typedef NS_ENUM(char, iPhoneModel){  //0~3

    iPhone4,//320*480

    iPhone5,//320*568

    iPhone6,//375*667

    iPhone6Plus,//414*736

    UnKnown

    };

    - (iPhoneModel)iPhonesModel {

    CGRect rect = [[UIScreen mainScreen] bounds];

    CGFloat width = rect.size.width;

    CGFloat height = rect.size.height;

    //get current interface Orientation

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    //unknown

    if (UIInterfaceOrientationUnknown == orientation) {

    return UnKnown;

    }

    if (UIInterfaceOrientationPortrait == orientation) {

    if (width ==  320.0f) {

    if (height == 480.0f) {

    return iPhone4;

    } else {

    return iPhone5;

    }

    } else if (width == 375.0f) {

    return iPhone6;

    } else if (width == 414.0f) {

    return iPhone6Plus;

    }

    }else if (UIInterfaceOrientationLandscapeLeft == orientation || UIInterfaceOrientationLandscapeRight == orientation) {

    //landscape

    if (height == 320.0) {

    if (width == 480.0f) {

    return iPhone4;

    } else {

    return iPhone5;

    }

    } else if (height == 375.0f) {

    return iPhone6;

    } else if (height == 414.0f) {

    return iPhone6Plus;

    }

    }

    return UnKnown;

    }

    ```

    相关文章

      网友评论

          本文标题:判断机型

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