0

正如主题中所述,这里发生了一些非常奇怪的事情;)我使用的是 xcode 4.02,iOS 4.3.4

我有一个 ViewController,在 xib 中有两个视图。ViewController 标头具有:

IBOutlet UIView* ViewPortrait;
IBOutlet UIView* ViewLandscape;

根据它们的方向,它们从文件所有者与 xib 中的两个视图连接。通用视图与这些视图之一(纵向)相关联。

在 viewDidLoad 我设置

self.view = ViewPortrait;

所以,总的来说,我的问题是,当我使用时,更改的“动画”并不总是有效(只是前两次)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
        self.view = ViewLandscape;
    } else {
        self.view = ViewPortrait;
    }
    return YES;
}

但是方向设置正确。当我在 ADDITION(!) 中使用它时:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [UIView animateWithDuration:duration
                     animations:^{
                         if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
                         {                       
                             self.view = SpeechToTextLandscape;                                     
                         }
                         else
                         {
                             self.view = SpeechToTextPortrait;
                         }

                     }];
}

动画效果几乎完美,除了一个现象:如果我顺时针旋转 iphone x 次,一切正常,第一次逆时针旋转时,视图本身正在变化,没有任何效果,但框架(尤其是状态栏)旋转了像往常一样的动画。同样,当我逆时针旋转 iphone x 次而不是第一次顺时针旋转时。改变方向后(除了第一次提到的)所有在同一方向的循环旋转都按预期设置动画。

如果我顺时针/逆时针旋转(左、右、左、右等),我总是会产生这种奇怪的效果:视图本身会立即交换,并且状态栏的“框架”会在大约一秒钟内被动画化。

所以,我很困惑,因为我这里有一些小的示例应用程序,完全正确地进行视图的动画交换,仅使用来自 shouldAutorotateToInterfaceOrientation 的代码(但我知道,它应该在 willAnimateRotationToInterfaceOrientation 中完成)。

无论如何,欢迎所有想法和建议!

最好的问候,吉米

4

0 回答 0