Bug fixes caused by changes in status bar on iOS top

Source: Internet
Author: User

Recently encountered a bug, found that when the status bar changes (such as the opening hotspot, another background to get the location, etc.), some view will be moved down, and some view will not move down, if the bottom of the view will cause a bug after the move. So I explored it and made a summary. What changes will be made to the status bar? When the status bar appears, the frame of the current view's root view will change, its Y value will increase by 20, and the height will be reduced by 20. and [UIScreen mainscreen].bounds and [UIApplication sharedapplication].keywindow.bounds These two methods get the frame is not changed (always equal to the screen size). So it's easy to write a bug that causes the view to move down when the status bar changes. the status bar appears in several cases1, the view is created when there is a status bar 2, the view created when there is no status bar, view display completely before the status bar appears Solution IdeasThe easiest way to do this is to use AutoLayout to constrain, and the bottom view must be constrained from the bottom so that neither the first case nor the second will produce a bug. or use autoresizing, which is set view.autoresizingmask = uiviewautoresizingflexiblewidth|  Uiviewautoresizingflexibleheight; If the AutoLayout and autoresizingmask are not used · There is already a status bar when the view is created, this is a simple case, do not use [UIScreen mainscreen].bounds and [uiapplication sharedapplication] when we write frame to get the current view size. Keywindow.bounds these two methods, instead of [UIApplication sharedapplication]. KeyWindow.rootViewController.view.bounds this to get the result is the view size when there is currently no status bar. There is no status bar when view is created, the status bar appears completely after the view has been created this is the case when the status bar is dynamically changed when we write the code, and we have to be compatible with it in order to avoid bugs. This situation, in addition to using AutoLayout to create a view, the other way is to listen to the status bar change notification, and after receiving the notification to the dynamic adjustment. some suggestions1. If you want to get the size of the current view (not the screen size), we recommend that you use [UIApplication sharedapplication].keywindow.rootviewcontroller.view.bounds 2, Use AutoLayout or autoresizing with a simple view at the bottom and constrain from the bottom (so you can avoid the bug completely) 3, if the view is created with frame, and the view is close to the bottom, be sure to consider when the status bar changes and the view move down may cause occlusion, So this is the only time to listen to the notification and make a dynamic change or use autoresizing. If you have any questions, welcome to add QQ Group test get started big God 755431660 learn together ~
???

Bug fixes caused by changes in status bar on iOS top

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.