UI rotation with device adaptation strategies from iOS6 to IOS8

Source: Internet
Author: User

- (void)statusBarOrientationChange:(NSNotification*)notification

{      WClassAndFunctionName;      UIInterfaceOrientation oriention = [UIApplication sharedApplication].statusBarOrientation;      [ self adaptUIBaseOnOriention:oriention]; }

In general, the Autoresizingmask property of the view comes with the fit of the screen rotation to easily fit the width and margin, and from IOS6 to IOS8. However, the premise is "under normal circumstances". When you need to have a different layout for the view you've encapsulated in a horizontal screen and a vertical screen, the Autoresizingmask property doesn't look like a restart. This is the main problem to be solved in this paper.

Obviously, detecting a view rotation event is something that must be done. In general, we encapsulate a custom control and always want the caller to be able to invoke it easily, so the detection view rotation should also be done within the control.

Start detecting view rotation.

Registering notifications in the Init method

- (void)registerListeningDeviceOriention

{      [[ NSNotificationCenter defaultCenter] addObserver: self                                               selector: @selector (statusBarOrientationChange:)                                                   name:UIApplicationDidChangeStatusBarOrientationNotification                                                 object: nil ]; }

Once the screen has rotated, call the Statusbarorientionchange: method. Like what:

123456 < Code class= "OBJC Plain" >-( void ) Statusbarorientationchange: ( nsnotification   *) notification {      wclassandfunctionname; &NBSP;&NBSP;&NBSP;&NBSP; uiinterfaceorientation oriention = [UIApplication sharedapplication].statusbarorientation ; &NBSP;&NBSP;&NBSP;&NBSP; [ self   Adaptuibaseonoriention:oriention]; //such as change Self.frame

However, things are not so smooth and take for granted! When you confidently in the Adaptuibaseonoriention method according to the Oriention layout will find thatIOS8 run out of the effect is perfect, and not the iOS8 version is a mess . Many times the layout of the subviews of a custom view (hereinafter referred to as Superview) depends on the size of the Superview. So once the Superview frame does not fit well, it looks like a mess! Why do these differences occur? The root cause is that Statusbarorientationchange's trigger time depends on the iOS version. After playing log found, IOS8 and above version, statusbarorientationchange after the rotation of the end of the call; in iOS8 the following version, Statusbarorientationchange is called before rotation . And if you take it for granted in the Statusbarorientationchange method to read the current device height and width, that inevitably produces a difference!

The overall idea is correct, the next step is to face the current device direction in the Statusbarorientationchange and the system version to judge, so as to get the true height and width of the device, the true height of the device is crucial to the layout!

CGFloat windowWidth = kDeviceWindowWidth4Panel;//iOS8不用更改

CGFloat windowHeight = kDeviceWindowHeight4Panel; if (!IsIOS8orAbove) {      windowWidth = (!kIsDeviceLandscape) ? kDeviceWindowWidth4Panel:kDeviceWindowHeight;      windowHeight = (!kIsDeviceLandscape) ? kDeviceWindowHeight4Panel:(kDeviceWindowWidth - (IsIOS7orAbove ? 0 : kSystemStatusBarHeight)); }

In fact, can be briefly described as: IOS8 on the windowsize is the current moment of the windowsize value, so can be directly assigned, iOS8 below the windowsize is the next moment after the rotation of the value, equivalent to pre-judgment.

The last point to note is that if you need to manually change the Superview frame in the Statusbarorientationchange method, please comment out all the autoresizingmask attributes in the Init method, Because the two are conflicting, especially under the iOS8. Because the iOS8 below essentially rotates all of the subviews's layouts to a rotated state before the rotation, the flip-over can be displayed normally. If you add the Autoresizingmask property, the system will fit according to the last moment before the rotation, so the rotation is macabre.

Portal:

Http://www.cnblogs.com/wengzilin/p/4236582.html

UI rotation with device adaptation strategies from iOS6 to IOS8

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.