/*
----------使用KVO強制修改設備方向達到橫豎屏轉變-----------
這種方法的表現是:statusBar會跟著屏幕做旋轉動畫。而且視圖中的其他控件會轉到橫屏布局
注意:這個方法不是官方提供的API.隨著系統版本的更迭有可能會失效
*/
//豎屏點擊按鈕 旋轉到橫屏
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];//這句話是防止手動把設備置為橫屏,導致下面的語句失效
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
isPortrait = NO;
//? ? 橫屏點擊按鈕, 旋轉到豎屏
//? ? [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];//這句話是防止手動先把設備置為豎屏,導致下面的語句失效.
//? ? [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
//? ? isPortrait= YES;
//同時還要必須支持自動旋轉
- (BOOL)shouldAutorotate
{
return YES;
}
//然后就是
- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice].model isEqualToString:@"iPhone"]&&isPortrait) { //如果是iPhone,且為豎屏的時候, 只支持豎屏
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskLandscape; //否者只支持橫屏
}