2

私は、向きの変化を処理するために、横向きと縦向きのビューコントローラーを別々に設定する方法を検討してきました。以下に投稿されたコードは、これを行う方法を示す Apple からのものです。私は、彼らが performSegueWithIdentifier を使用していることに気付きました。セグエが使用されているのは奇妙に思えます。

ストーリーボードにセグエを作成するには、非表示のボタンを作成し、ポートレート ビュー コントローラーからランドスケープ ビュー コントローラーに接続をドラッグする必要があると想定しています。次に、セグエ識別子を「DisplayAlternateView」に設定できます。デフォルトのセグエ アニメーションは何ですか? または、アニメーションをオフにするのがデフォルトですか?

また、このコードがawakeFromNibメソッドにあるのはなぜですか? それはviewDidLoadにあるべきではありませんか?viewDidLoad の前に awakeFromNib が呼び出されますか?

また、ストーリーボードのシーンごとに異なるターゲット アクションが必要であると想定しています。縦向きのビュー A、B、C に対応する横向きのビュー A、B、C がある場合、Apple コードに次の変更を加える必要があります。

私のAビューで:

   selector:@selector(orientationChangedA:)

それから私のBで

   selector:@selector(orientationChangedB:)

それから私のCで

   selector:@selector(orientationChangedC:)

このようにして、各メソッドは独自のセグエを実行できます。

ここで物事を複雑にしすぎているように感じます。別々のセグエが余分な作業をさせているのでしょうか、それとも別々のView Controllerへの向きの切り替えが通常どのように処理されるのでしょうか?

これは、さまざまなView Controllerで向きの変更を処理する方法を示すAppleのコードです。

@implementation PortraitViewController

- (void)awakeFromNib

{

isShowingLandscapeView = NO;

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] addObserver:self

                             selector:@selector(orientationChanged:)

                             name:UIDeviceOrientationDidChangeNotification

                             object:nil];

}



- (void)orientationChanged:(NSNotification *)notification

{

UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

if (UIDeviceOrientationIsLandscape(deviceOrientation) &&

    !isShowingLandscapeView)

{

    [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];

    isShowingLandscapeView = YES;

}

else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&

         isShowingLandscapeView)

{

    [self dismissViewControllerAnimated:YES completion:nil];

    isShowingLandscapeView = NO;

}

}
4

0 に答える 0