View Controller Rotation

Source: Internet
Author: User

// Controls whether the current view Controller supports rotation.
-(Bool) shouldautorotate // auto rotate
{
Return yes;
}
// Sets the orientation of screen rotation. By default, the system supports rotation in three directions, vertical and Left and Right horizontal screens.
// Uiinterfaceorientationmaskportrait is in the positive direction in the vertical direction.
// Uiinterfaceorientationmasklandscapeleft left landscape
// Uiinterfaceorientationmasklandscaperight right landscape
// Uiinterfaceorientationmasklandscape landscape
-(Nsuinteger) supportedinterfaceorientations
{
Return uiinterfaceorientationmaskall;
}
// Triggered when the screen is about to rotate (the screen is not yet rotated)
-(Void) willrotatetointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation duration :( nstimeinterval) Duration
{
// When the screen is about to rotate, You need to pause music and video playback and disable user interaction.
Nslog (@ "% s" ,__ function __);
[Super willrotatetointerfaceorientation: tointerfaceorientation Duration: Duration];
}


// Triggered when the screen is rotated.
-(Void) willanimaterotationtointerfaceorientation :( uiinterfaceorientation) tointerfaceorientation duration :( nstimeinterval) Duration
{
// In this method, if you want to add your own animation when the screen is rotated, it is implemented in this method.

Nslog (@ "% s" ,__ function __);
[Super willanimaterotationtointerfaceorientation: tointerfaceorientation Duration: Duration];
}

// Triggered when screen rotation is complete.
-(Void) didrotatefrominterfaceorientation :( uiinterfaceorientation) frominterfaceorientation
{
Nslog (@ "% s" ,__ function __);
[Super didrotatefrominterfaceorientation: frominterfaceorientation];
// After rotation, continue playing the music, continue playing the video, and enable user interaction.
}


// Triggered when the view layout on the View Controller is re-deployed.
-(Void) viewwilllayoutsubviews
{

[Super viewwilllayoutsubviews];
// Nslog (@ "QC ");
}


-(Bool) textfieldshouldreturn :( uitextfield *) textfield
{
[Textfield resignfirstresponder];
Return yes;

}
-(Void) SEL :( uibutton *) BTN
{
// [_ TF resignfirstresponder];

}



// Release the memory temporarily unavailable for the current program.
-(Void) didreceivememorywarning
{
[Super didreceivememorywarning];
// Dispose of any resources that can be recreated.
// When receiving a memory warning, remove the view that is not displayed on the current screen.

// Determine whether the view of the controller can be safely removed
// Determine whether the view of the current view controller is displaying. Self. View. Window is nil;

// Determine whether the view of the current view controller is successfully loaded. isviewloaded view is loaded


If (! Self. View. Window & [self isviewloaded])
{
// Safely remove the Controller View
Self. view = nil; // equivalent to [_ view release]; _ view = nil;
}
// Nslog (@ "View: % @", self. View. Window );

}



// When the screen is rotated every time, the view layout method is triggered to re-layout the subview on The View.
-(Void) layoutsubviews
{
[Super layoutsubviews];
// Nslog (@ "QCC ");

// Re-layout the child view.
// The layout is determined based on the orientation of the screen rotation.
// 1. Get the statusbarorientation Status Bar Height 20 for the orientation of the screen

Switch ([uiapplication sharedapplication]. statusbarorientation ){
Case uiinterfaceorientationportrait:
// Nslog (@ "vertical (positive )");
// _ Button. Frame = cgrectmake (60,240,200, 40 );

Case uiinterfaceorientationportraitupsidedown:
// Nslog (@ "vertical direction (reverse )");
_ Button. Frame = cgrectmake (60,240,200, 40 );
Break;
Case uiinterfaceorientationlandscapeleft:
// Nslog (@ "Left ");
// _ Button. Frame = cgrectmake (320,160, 60, 40 );

Case uiinterfaceorientationlandscaperight:

// Set the display style of the landscape chart.
_ Button. Frame = cgrectmake (320,160, 60, 40 );
// Nslog (@ "Right Direction ");
Break;


Default:
Break;
}
}

View Controller 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.