About iOS6.0 screen Rotation

Source: Internet
Author: User

1. In appDelegate, there are two ways to add a view to a window,


[Cpp]
Self. window. rootViewController = self. view;
[Self. window addSubview: self. view. view];

Self. window. rootViewController = self. view;
[Self. window addSubview: self. view. view];
However, if the second method is used, setting screen rotation in ios6.0 does not have any effect. The first method must be used. There is no such difference in versions earlier than ios6.0.

2. enable screen rotation in all directions

Before iOS6.0: You only need this method to return yes.

[Cpp] www.2cto.com
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return YES;
}

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return YES;
} In iOS6.0, these three methods must be used together.

[Cpp]
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return (toInterfaceOrientation! = UIInterfaceOrientationMaskPortraitUpsideDown );
}
-(BOOL) shouldAutorotate
{
Return YES;
}
-(NSUInteger) supportedInterfaceOrientations
{
Return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return (toInterfaceOrientation! = UIInterfaceOrientationMaskPortraitUpsideDown );
}
-(BOOL) shouldAutorotate
{
Return YES;
}
-(NSUInteger) supportedInterfaceOrientations
{
Return UIInterfaceOrientationMaskAllButUpsideDown;
} Of course, you can change the above return value to no if you disable the rotation of the screen in all directions.

Before iOS6.0:

[Cpp]
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return NO;
}

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return NO;
} IOS6.0

[Cpp]
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return (toInterfaceOrientation = UIInterfaceOrientationPortrait );
}
-(BOOL) shouldAutorotate
{
Return NO;
}
-(NSUInteger) supportedInterfaceOrientations
{
Return UIInterfaceOrientationMaskPortrait; // only this direction is supported (normal direction)
}

-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation
{
Return (toInterfaceOrientation = UIInterfaceOrientationPortrait );
}
-(BOOL) shouldAutorotate
{
Return NO;
}
-(NSUInteger) supportedInterfaceOrientations
{
Return UIInterfaceOrientationMaskPortrait; // only this direction is supported (normal direction)
}

Common Methods for screen Rotation

[Cpp]
// Automatically called before view Rotation
-(Void) willRotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation duration :( NSTimeInterval) duration {
NSLog (@ "automatically called before view rotation ");
}
// It is automatically called when the rotation direction of the view changes.
-(Void) willAnimateRotationToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation duration :( NSTimeInterval) duration
{
NSLog (@ "automatically called when the view rotation direction changes ");
}
// The view is automatically called after rotation.
 
-(Void) didRotateFromInterfaceOrientation :( UIInterfaceOrientation) fromInterfaceOrientation {
NSLog (@ "automatically called after view rotation ");
}

// Automatically called before view Rotation
-(Void) willRotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation duration :( NSTimeInterval) duration {
NSLog (@ "automatically called before view rotation ");
}
// It is automatically called when the rotation direction of the view changes.
-(Void) willAnimateRotationToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation duration :( NSTimeInterval) duration
{
NSLog (@ "automatically called when the view rotation direction changes ");
}
// The view is automatically called after rotation.

-(Void) didRotateFromInterfaceOrientation :( UIInterfaceOrientation) fromInterfaceOrientation {
NSLog (@ "automatically called after view rotation ");
}


 

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.