// 强制横屏的一种实现
// 使用方法:
// 在vc的init方法中调用initLogic
// 在vc关闭之前调用cleanRotateTrace方法
-(void)initLogic
{
isPortraitIn_ = NO;
isSettingStatusBar_ = NO;
}
-(BOOL)shouldAutorotate
{
if (isSettingStatusBar_)
{
return NO;
}
return YES;
}
-(NSUInteger)supportedInterfaceOrient ations
{
return UIInterfaceOrientationMa skLandscape;
}
-(BOOL)shouldAutorotateToInterf aceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationLa ndscapeLeft)||(toInterfaceOrientation == UIInterfaceOrientationLa ndscapeRight));
}
- (void)willRotateToInterfaceOri entation:(UIInterfaceOrientation)toInterfaceOrientationduration:(NSTimeInterval)duration
{
if (isPortraitIn_)
{
self.view.transform = CGAffineTransformIdentit y;
isPortraitIn_ = NO;
}
}
- (void)cleanRotationTrace
{
if (isPortraitIn_)
{
self.view.transform = CGAffineTransformIdentit y;
isPortraitIn_ = NO;
UIInterfaceOrientation orientation = [UIApplicationsharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLa ndscapeRight)
{
isSettingStatusBar_ = YES;
[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPo rtrait animated:NO];
isSettingStatusBar_ = NO;
}
else
{
isSettingStatusBar_ = YES;
[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPo rtraitUpsideDown animated:NO];
isSettingStatusBar_ = NO;
}
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.height + 20,self.view.frame.size.width - 20)];
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIInterfaceOrientation orientation = [UIApplicationsharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIs Portrait(orientation))
{
isPortraitIn_ = YES;
self.view.transform = CGAffineTransformMakeRot ation(M_PI_2);
if (orientation == UIInterfaceOrientationPo rtrait)
{
isSettingStatusBar_ = YES;
[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationLa ndscapeRight animated:NO];
isSettingStatusBar_ = NO;
}
else
{
isSettingStatusBar_ = YES;
[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationLa ndscapeLeft animated:NO];
isSettingStatusBar_ = NO;
}
[self.view setFrame:CGRectMake(0, -20, self.view.frame.size.height - 20,self.view.frame.size.width + 20)];
}
}
// 使用方法:
// 在vc的init方法中调用initLogic
// 在vc关闭之前调用cleanRotateTrace方法
-(void)initLogic
{
}
-(BOOL)shouldAutorotate
{
}
-(NSUInteger)supportedInterfaceOrient
{
}
-(BOOL)shouldAutorotateToInterf
{
}
- (void)willRotateToInterfaceOri
{
}
- (void)cleanRotationTrace
{
}
-(void)viewDidAppear:(BOOL)animated
{
}