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