1

RootViewController によって制御される複数の UIViewControllers を使用してアプリケーションを構築しています。現在、plist では、アプリケーションのデフォルトは LandscapeRight です。

RootViewController にロードできる次のファイルがあるとします。

  1. IntroView (横向き右のみ)
  2. LandscapeView (横向き右のみ)
  3. PortraitView (縦長のみ)

また、RootViewController の shouldAutorotateToInterfaceOrientation に以下を追加しました。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([currentClass class] == PortraitView.class) {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

} else {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

}

したがって、PortraitView と viewWillAppear にロードするまで、すべて問題ありません。次を追加します (このスレッドに似ています)。

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {      

    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
    self.view.center = CGPointMake(240.0f, 160.0f);

}


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

これにより、PortraitView に適切に読み込まれますが、PortraitView 内に 2 つのサブビューがあり、それらを切り替えたいのですが、ビューを回転させたため、UIViewAnimationTransitionFlipFromLeft により、実際には左から右ではなく上から下に反転します。PortraitViewにそれがPortraitであることを伝える方法を私は一生理解できません。

[[UIDevice currentDevice] の向き] を確認すると、ランドスケープであることがわかります。shouldAutorotateToInterfaceOrientation を使用して Portrait only に設定しようとすると、ビューが回転するため、正しくなくなります。

うまくいけば、これは理にかなっています!一日中この問題を見ています。

ありがとう!

4

1 に答える 1

0

私はこれに少し違った方法で遭遇しました。UIViewController左から右ではなく上から下にスワップするランドスケープモードのサブクラス。

私のために働いた修正は、すべてのビューを単一の「内部」ビューに追加してから、UIViewController通常のビューの代わりにそれを反転することでしたview

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:[self innerView]
                             cache:YES];

[self innerView]の唯一の子はどこ[self view]にあり、すべてのサブビューはその中にあります。

于 2011-03-30T01:43:50.910 に答える