UIScreen and ios8UIScreen in ios8

Source: Internet
Author: User

UIScreen and ios8UIScreen in ios8
Java code

  • Let orientation: UIInterfaceOrientation = UIApplication. sharedApplication (). statusBarOrientation
  • Println ("Currently landscape:" + (orientation = UIInterfaceOrientation. LandscapeLeft | orientation = UIInterfaceOrientation. LandscapeRight )? "YES": "NO "))
  • Println ("UIScreen. mainScreen (). bounds: \ (UIScreen. mainScreen (). bounds )")
  • Println ("UIScreen. mainScreen (). applicationFrame: \ (UIScreen. mainScreen (). applicationFrame )")
  •    let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation        println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO"))        println("UIScreen.mainScreen().bounds: \(UIScreen.mainScreen().bounds)")        println("UIScreen.mainScreen().applicationFrame: \(UIScreen.mainScreen().applicationFrame)")

    Output in ios7:

    Currently landscape: NO

    UIScreen. mainScreen (). bounds: (0.0, 0.0, 320.0, 568.0)

    UIScreen. mainScreen (). applicationFrame: (0.0, 20.0, 320.0, 548.0)

    Currently landscape: YES

    UIScreen. mainScreen (). bounds: (0.0, 0.0, 320.0, 568.0)

     

    UIScreen. mainScreen (). applicationFrame: (20.0, 0.0, 300.0, 568.0)

     

    Output in ios8:

    Currently landscape: NO

    UIScreen. mainScreen (). bounds: (0.0, 0.0, 320.0, 568.0)

    UIScreen. mainScreen (). applicationFrame: (0.0, 20.0, 320.0, 548.0)

    Currently landscape: YES

    UIScreen. mainScreen (). bounds: (0.0, 0.0, 568.0, 320.0)

    UIScreen. mainScreen (). applicationFrame: (0.0, 0.0, 568.0, 320.0)

     

    Conclusion:

    1. In ios7, UIScreen. mainScreen (). bounds is a fixed value. In ios8. its value changes with the landscape and landscape!

    In order to get the original effect in ios8:

    Java code
  • + (CGSize) screenSize {
  • CGSize screenSize = [UIScreen mainScreen]. bounds. size;
  • Return CGSizeMake (MIN (screenSize. width, screenSize. height), MAX (screenSize. width, screenSize. height ));
  • }
  • + (CGSize)screenSize {    CGSize screenSize = [UIScreen mainScreen].bounds.size;    return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));}

     

    2,

    Two attributes are added to ios8:

    NativeBounds: screen pixels, which do not change horizontally or vertically!

    NativeScale: 1 (non retina)/2 (retina)/3 (retina hd)

    Https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreen_Class/index.html#//apple_ref/occ/instp/UIScreen/nativeBounds

    Ios8 output:

    Currently landscape: YES

    UIScreen. mainScreen (). bounds: (0.0, 0.0, 568.0, 320.0)

    UIScreen. mainScreen (). applicationFrame: (0.0, 20.0, 568.0, 300.0)

    UIScreen. mainScreen (). nativeBounds: (0.0, 0.0, 640.0, 1136.0)

    UIScreen. mainScreen (). nativeScale: 2.0

    Currently landscape: NO

    UIScreen. mainScreen (). bounds: (0.0, 0.0, 320.0, 568.0)

    UIScreen. mainScreen (). applicationFrame: (0.0, 20.0, 320.0, 548.0)

    UIScreen. mainScreen (). nativeBounds: (0.0, 0.0, 640.0, 1136.0)

     

    UIScreen. mainScreen (). nativeScale: 2.0

     

    3. The output value of UIScreen. mainScreen (). applicationFrame indicates that the statusbar of ios8 is hidden by default. You can

    View controller-based status bar appearance values are different

     

    Java code
  • UIApplication. sharedApplication (). setStatusBarHidden (false, withAnimation: UIStatusBarAnimation. None)
  • UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)

     

    Or

    Java code
  • Override func prefersStatusBarHidden ()-> Bool {
  • Return false
  • }
  •   override func prefersStatusBarHidden() -> Bool {        return false     }

    Display landscape statusbar

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.