1

我正在构建一个由 RootViewController 控制的具有多个 UIViewController 的应用程序。目前在 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 并将其设置为仅纵向时,它将旋转我的视图,因此它不再正确。

希望这是有道理的!整天都在看这个问题。

谢谢!

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 回答