iOS interface layout Toggle and Control Adaptive (recommended)

Source: Internet
Author: User

 iOS interface layout Toggle and Control Adaptive (recommended)Category: "Mac/ios under development"2013-11-06 15:14 8798 People read comments (0) favorite reports Toggle Adaptive on/off screen

The first is to change the properties of view.transform by artificial means.

Specific measures:

View.transform is generally a view of the rotation, stretching movement and other properties, similar to View.layer.transform, the difference is View.transform is two-dimensional, that is, the use of affine method is usually prefixed with the Cgaffinetransform class (you can go to the API document to search the prefix of all classes), The view.layer.transform can be changed in 3D mode, usually using a class prefixed with catransform3d.

One thing to remember here is that when you change a View.transform property or view.layer.transform You need to restore the default state, remember to reset them first to use View.transform = Cgaffinetransformidentity, or view.layer.transform = Catransform3didentity, Assuming you're constantly changing a view.transform property, and you don't reset it before each change, you'll see that the changes you've made and what you want are changing, not the results you really want.

Well, the properties of rotation are described above, and the next is the key. An official offer is to check the status of the current battery bar uiinterfaceorientation orientation = [UIApplication sharedapplication].statusbarorientation; This way, you can know the current screen of the battery bar display direction, and you can also force the setting of his display direction, by setting this property is OK, you can choose whether to animate the direction of the battery bar. With these two, we can arbitrarily change the way we want to display.

1. Get the current battery bar direction uiinterfaceorientation orientation = [UIApplication sharedapplication].statusbarorientation

2. Get the current screen size cgrect frame = [UIScreen mainscreen].applicationframe;

3. Set the center point of our view
Cgpoint Center = cgpointmake (frame.origin.x + ceil (FRAME.SIZE.WIDTH/2), FRAME.ORIGIN.Y + ceil (FRAME.SIZE.HEIGHT/2));

4. Depending on the direction of the current battery bar, get the size of the angle you want to rotate. Usually

if (orientation = = Uiinterfaceorientationlandscapeleft) {
        return Cgaffinetransformmakerotation (m_pi*1.5);
   } else if (orientation = = uiinterfaceorientationlandscaperight) {
    & nbsp;   return cgaffinetransformmakerotation (M_PI/2);
   } else if (orientation = = Uiinterfaceorientationportraitupsidedown) {
         return cgaffinetransformmakerotation (-M_PI);
   } else {
        return cgaffinetransformidentity;
   }

5. We can animate the way our view is displayed.
[[UIApplication sharedapplication] Setstatusbarorientation:uideviceorientationlandscaperight Animated:YES];

CGFloat duration = [UIApplication sharedapplication].statusbarorientationanimationduration; (Gets the time of the current battery bar animation change)
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:duration];

Here you set the View.transform to match the size of the rotation angle.

[UIView commitanimations];

iOS interface layout Toggle and Control Adaptive (recommended)

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.