iOSシングルページ設定水平画面

私たちの開発では、水平画面ブラウジングを設定する必要がある場合があります。特に、ビデオ再生ページは水平画面によく使用され、水平画面と垂直画面を切り替えるためにも最もよく使用されます。

では、水平画面をどのように設定して適応させる必要がありますか?

 1.ページのデフォルトの水平画面効果を入力します

  1. ページ画面の向きを設定する
  2. ページ画面のサポートされている向きを設定します
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}//页面需要的横屏方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}//页面支持屏幕横屏的方向

 ページBの設定を追加すると、ページAはページBに入り、ページBは水平になりますが、

[自己presentViewController:vcanimated:YEScompletion:nil]これはBページに入るときに有効になり、プッシュエントリは有効になりません

2.水平画面を手動で設定するコード

  1. ページ画面の向きを設定する
  2. ページ画面のサポートされている向きを設定します
  3. 手動呼び出し
- (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"];
}

ボタンをクリックして呼び出し、画面の向きを設定します

- (void)changeUIDeviceOrientation:(UIButton *)sender {
   [self forceToOrientation:UIDeviceOrientationLandscapeRight];
}

viewDidLoadで設定すると、自動的にページに入ることができます水平画面(プッシュ)

- (void)viewDidLoad {
    [super viewDidLoad];

	[self forceToOrientation:UIDeviceOrientationLandscapeRight];

}

 

おすすめ

転載: blog.csdn.net/zjpjay/article/details/103984174