1, do not directly in the UIWindow directly using the UIView, but load the root to try to control (Uiviewcontroller) and then use the controller to change UIView, which is Apple's official recommended way
[Self Beginappearancetransition:yes animated:no]; [Parentviewcontroller addchildviewcontroller:self]; [Parentviewcontroller.view AddSubview:self.view]; [Self didmovetoparentviewcontroller:self]; [Self endappearancetransition];
2.
In a horizontal screen app, use Keywindow to add a view, toggle the device landscape orientation, and discover that the added view does not change direction.
And only the rootviewcontroller of window can hear the change of the screen rotation.
[[Uiapplicationsharedapplication].keywindow Addsubview:view];
Here's how to fix it:
Define Rotatewindow inheritance UIWindow, and override the Addsubview method. The window in Appdelegate uses Rotatewindow.
#define Degreestoradian (x) (M_PI * (x)/180.0)-(void) Addsubview: (UIView *) View { If1) { float angle = ([uidevice currentdevice].orientation = = Uideviceorientationlandscapeleft)? *:--; = cgaffinetransformmakerotation (Degreestoradian (angle)); 0 0 ); } [Super Addsubview:view];}
Define Rotateviewcontroller as the rootviewcontroller of the window and override the following methods
//horizontal screen only allowed-(BOOL) shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation {//Return YES for supported orientations. return(interfaceorientation = = Uiinterfaceorientationlandscapeleft | | interfaceorientation = =uiinterfaceorientationlandscaperight);}//Modify Add view orientation when device is rotated- (void) Willrotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: (NSTimeInterval) Duration {UIWindow*window =[UIApplication Sharedapplication].keywindow; inti =0; for(UIView *viewinchwindow.subviews) {if(I! =0) {Cgaffinetransform transform=View.transform; Transform= Cgaffinetransformrotate (Transform, Degreestoradian ( the)); View.transform=transform; } I++; }}3, Methods:-(void) Rotateview {UIWindow*keywindow =[[UIApplication sharedapplication] Keywindow]; UIView*bgview =[[UIView alloc] initWithFrame:keywindow.bounds]; [Keywindow Addsubview:bgview]; [Bgview release]; [Bgview Addsubview:_overlayview]; [Bgview addsubview:self]; Self.center= Cgpointmake (keywindow.bounds.size.width/2.0f, Keywindow.bounds.size.height/2.0f); //Rotate the image by the specific angle.[Bgview settransform:cgaffinetransformmakerotation (angle)]; [Self fadeIn]; }
Originating From: http://blog.csdn.net/leikezhu1981/article/details/38072221
Horizontal screen UIWindow Add multiple view auto-rotation solutions