Recently the screen, get some experience, special record down.
The most important thing is to determine the interface of the screen response. There are two ways I know now:
1. Use notifications.
-(void) viewdidload
{
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (_orientationdidchange:) Name: Uideviceorientationdidchangenotification Object:nil];
}
-(void) Dealloc {
[[Nsnotificationcenter Defaultcenter] removeobserver:self name:uideviceorientationdidchangenotification object:nil ]; }
-(void) _orientationdidchange: (nsnotification*) Notify
{
[Self _shouldrotatetoorientation: (uideviceorientation) [UIApplication sharedapplication].statusbarorientation];
}
-(void) _shouldrotatetoorientation: (uideviceorientation) Orientation {
if (orientation = = Uideviceorientationportrait | | Orientation = = Uideviceorientationportraitupsidedown) {
Vertical screen
}
else {
Horizontal screen
}
}
The above code, a look will understand.
2. Using Viewwilllayoutsubviews
When the test finds the screen switching, the system responds to some functions, one of which is viewwilllayoutsubviews.
-(void) viewwilllayoutsubviews
{
[Self _shouldrotatetoorientation: (uideviceorientation) [UIApplication sharedapplication].statusbarorientation];
The interface between the screen and the switch is known through one of these functions.
Attention:
Viewwilllayoutsubviews can only be used in Viewcontroller, there is no response in view.