1

ナビゲーションバーの高さサイズを考慮した正しいコンテンツフレームサイズを取得しようとしています。
ただし、willRotateTo〜メソッドでNSLogを使用してフレームサイズを出力すると、以前のフレームサイズが表示されます。
ただし、didRotateFrom〜メソッドで正しいフレームサイズが表示されます。
willRotateTo〜メソッドでdidRotateFrom〜のサイズのようなフレームサイズを取得するにはどうすればよいですか?

以下はAppDelegate.mです

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    ViewController *rootView = [[[ViewController alloc] init] autorelease];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[[UINavigationController alloc] initWithRootViewController:rootView] autorelease];

    } else {
        self.viewController = [[[UINavigationController alloc] initWithRootViewController:rootView] autorelease];
    }

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}


そして次はViewController.mです

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSLog(@"willRotate size is width : %f  height : %f", self.view.frame.size.width, self.view.frame.size.height);
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    NSLog(@"didRotate size is width : %f  height : %f", self.view.frame.size.width, self.view.frame.size.height);
}


横向きに回転させた場合の結果は以下のとおりです。

ここに画像の説明を入力してください

/Users/nice7285/Library/Caches/appCode10/DerivedData/testView-d007adbb/Build/Products/Debug-iphonesimulator/testView.app/testView
Simulator session started with process 3896
2012-10-11 04:28:59.719 testView[3896:11303] willRotate size is width : 320.000000  height : 416.000000
2012-10-11 04:29:00.025 testView[3896:11303] didRotate size is width : 480.000000  height : 268.000000
4

2 に答える 2

7

受け入れられた答えは、直面している問題を実際には解決しません。didRotateFromInterfaceOrientation で UI の変更を実行すると、画面が回転アニメーションを実行した後に UI の変更が行われます。これは本当に醜く突然に見えます。

willAnimateRotationToInterfaceOrientation を使用する必要があります。これは、回転が発生した後に呼び出され、境界が再計算され、アニメーションの UI コントロールをセットアップできるようになります。これにより、ある方向から別の方向へのスムーズな移行を実行できます。

于 2014-10-24T22:55:47.860 に答える
0

の理由self.view.framewillRotateToInterfaceOrientation、ビューがまだ回転されていないため、回転前の寸法を示しているため、フレームはまだ変更されていません。その時点でわかる唯一のことは、回転している向きだけです。その関数で新しい次元が必要な場合は、それらを自分でハードコーディングする必要があります。didRotateFromInterfaceOrientationただし、必要なことはすべて実行できるはずなので、これを行う必要はありません。

于 2012-10-10T20:20:59.340 に答える