0

これが私が苦労してきた問題です:

viewloadView を使用してプログラムで作成しています。読み込まれると、ポートレート ビューで見栄えがよくなります。ただし、デバイスの回転を処理したい。したがって、私はwillAnimateRotationToInterfaceOrientation方法を使用します。

このメソッド内で、すべての要素を調整する関数を呼び出します。その関数が行うことは、すべてのビューを通過し、CGRectそれぞれに新しい設定を行うことです。縦向き (上下逆さま) では問題なく動作しますが、向きを横向きに変更するとトリミングされます。

2 つの質問:

  1. そのような行動の最も可能性の高い理由は何ですか?
  2. 水平方向/垂直方向の別のビューを作成せずに、デバイスの回転を処理する方法を提案してください。
4

1 に答える 1

0

重要な部分が欠けていると思います。ビューで縦向きのビューでフレームを設定している場合、ビューはフレームを取得しましたが、横向きに変更すると変更されますが、そこから縦向きのフレームを設定していないと思います。使用通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];


-(void) orientationChanged:(NSNotification *)notification
{
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{

        UIDeviceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

        if((orientation == UIDeviceOrientationPortrait) || (orientation == UIDeviceOrientationPortraitUpsideDown)) {
           // set frame here
        }else if ((orientation == UIDeviceOrientationLandscapeLeft) || (orientation == UIDeviceOrientationLandscapeRight)){
          // set frame here too
        }
    }];
}
于 2013-10-30T13:35:08.843 に答える