#import "RotationTool.h"
@implementation RotationTool
static UIDeviceOrientation ScreenOrient;
+(void)setScreenOrientation :(UIDeviceOrientation) orient
{
ScreenOrient = orient;
}
+(UIDeviceOrientation) getScreenOrientation
{
return ScreenOrient;
}
@end
按钮点击事件增加如下代码:
if([RotationTool getScreenOrientation]==UIDeviceOrientationLandscapeLeft){
[RotationTool setScreenOrientation:UIDeviceOrientationLandscapeRight];
}else{
[RotationTool setScreenOrientation:UIDeviceOrientationLandscapeLeft];
}
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
if ([RotationTool getScreenOrientation] == UIInterfaceOrientationLandscapeLeft) {
self.view.transform = CGAffineTransformMakeRotation(2*M_PI);
} else if ([RotationTool getScreenOrientation] == UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformMakeRotation(M_PI);
} else {
self.view.transform = CGAffineTransformIdentity;
}
[UIView commitAnimations];