1. 在AppDelegate.h文件中 聲明一個變量,
@property?(nonatomic,?assign)?NSInteger?rotateDirection;
2. ?在AppDelegate.m文件中 加一個判斷旋轉(zhuǎn)函數(shù)
//此方法會在設備橫豎屏變化的時候調(diào)用
- (UIInterfaceOrientationMask)application:(UIApplication?*)application supportedInterfaceOrientationsForWindow:(UIWindow?*)window{
?if?(self.rotateDirection?== 1)
? ? {
?return?UIInterfaceOrientationMaskLandscapeRight; // 支持右屏旋轉(zhuǎn)
? ? }
?return?UIInterfaceOrientationMaskPortrait;
}
3.在需要橫屏的界面,橫屏的點擊方法里面
AppDelegate *appdelegate = ((AppDelegate *)[[UIApplication sharedApplication] delegate]);
//豎屏->橫屏
?if?(appdelegate.rotateDirection?== 0)
? ? {
?appdelegate.rotateDirection?= 1;
?if?([UIDevice?currentDevice].orientation?!= 1)
? ? ? ? {
? ? ? ? ? ? [[UIDevice?currentDevice]?setValue:[NSNumber?numberWithInteger:UIInterfaceOrientationPortrait]
?forKey:@"orientation"];
? ? ? ? }
? ? ? ? [[UIDevice?currentDevice]?setValue:[NSNumber?numberWithInteger:UIInterfaceOrientationLandscapeRight]
?forKey:@"orientation"];
? ? ? ? [[UIApplication?sharedApplication]?setStatusBarHidden:NO];
? ? ? ? [[UIApplication?sharedApplication]?setStatusBarOrientation:UIInterfaceOrientationLandscapeRight?animated:NO];
?self.playerView.frame?=?CGRectMake(0, 0,?ScreenWidth,?ScreenHeight); // 順便改下播放器的UI
? ? }
?else
? ? {
//橫屏------->豎屏
?appdelegate.rotateDirection?= 0;
?if?([UIDevice?currentDevice].orientation?!= 4)
? ? ? ? {
? ? ? ? ? ? [[UIDevice?currentDevice]?setValue:[NSNumber?numberWithInteger:UIInterfaceOrientationLandscapeRight]
?forKey:@"orientation"];
? ? ? ? }
? ? ? ? [[UIDevice?currentDevice]?setValue:[NSNumber?numberWithInteger:UIInterfaceOrientationPortrait]
?forKey:@"orientation"];
? ? ? ? [[UIApplication?sharedApplication]?setStatusBarHidden:NO];
? ? ? ? [[UIApplication?sharedApplication]?setStatusBarOrientation:UIInterfaceOrientationPortrait?animated:NO];
?self.playerView.frame?=?CGRectMake(0, 20,?ScreenWidth,?ScreenWidth?/ 16 * 9);// 順便改下播放器的UI
? ? }
}