我們在開發(fā)中刹泄,有些時(shí)候需要設(shè)置橫屏瀏覽,特別是視頻播放頁面是經(jīng)常用的到橫屏疏虫,也是橫屏和豎屏之間來回的切換運(yùn)用最多的永罚。
那么我們應(yīng)該怎么設(shè)置和適配橫屏呢?卧秘?呢袱?
?1.進(jìn)入頁面默認(rèn)橫屏效果
設(shè)置頁面屏幕屏幕方向
設(shè)置頁面屏幕支持的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
? ? return UIInterfaceOrientationLandscapeRight;
}//頁面需要的橫屏方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
? ? return UIInterfaceOrientationMaskLandscapeRight;
}//頁面支持屏幕橫屏的方向
?加入 B 頁面這樣設(shè)置,A 頁面進(jìn)入到 B 頁面翅敌,B 頁面就是橫屏的了羞福,不過需要注意的是,只有
[self? presentViewController:vc animated:YES completion:nil]? 這樣進(jìn)入 B頁面才會生效蚯涮,push 進(jìn)入的不會生效
2.代碼手動(dòng)設(shè)置橫屏
設(shè)置頁面屏幕屏幕方向
設(shè)置頁面屏幕支持的方向
手動(dòng)調(diào)用
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
? ? return UIInterfaceOrientationLandscapeRight;
}//頁面需要的橫屏方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
? ? return UIInterfaceOrientationMaskLandscapeRight;
}//頁面支持屏幕橫屏的方向
// 改變頁面屏幕方向的方法
- (void)forceToOrientation:(UIDeviceOrientation)orientation
{
? ? NSNumber *orientationUnknown = [NSNumber numberWithInt:0];
? ? [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
? ? NSNumber *orientationTarget = [NSNumber numberWithInt:orientation];
? ? [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}
點(diǎn)擊按鈕調(diào)用設(shè)置屏幕方向
- (void)changeUIDeviceOrientation:(UIButton *)sender {
? [self forceToOrientation:UIDeviceOrientationLandscapeRight];
}
在 viewDidLoad??里面設(shè)置也可以進(jìn)入頁面自動(dòng)橫屏( push)
- (void)viewDidLoad {
? ? [super viewDidLoad];
[self forceToOrientation:UIDeviceOrientationLandscapeRight];
————————————————