1

我想要做的是创建一个视图控制器,并让它的视图从右侧动画。主视图控制器有一个名为 viewContainer 的视图,它将容纳这个视图。奇怪的是,这在模拟器和 ipod 4g 上完美运行,但在 iPhone5 上不起作用(都运行 ios6)。

在 ipod 4g 上,新视图正确地从右侧动画化。然而,在 iPhone5 上,视图立即出现在 (0,0)。这可能是什么原因造成的?

self.catViewController = [[CatViewController alloc] initWithNibName:@"CatViewController" bundle:nil];
[self.catViewController willMoveToParentViewController:nil];

[self addChildViewController:self.catViewController];
self.currentViewController = self.catViewController;

[self showNextViewController];

- (void) showNextViewController
{

    NSLog(@"should be at x: %f", self.viewContainer.bounds.size.width); //This correctly logs 320 as the starting x position of the new view

    //set the new view's position off screen to the right
    self.currentViewController.view.frame = CGRectMake(self.viewContainer.bounds.size.width, self.viewContainer.bounds.origin.y, self.currentViewController.view.frame.size.width, self.currentViewController.view.frame.size.height);
    [self.viewContainer addSubview:self.currentViewController.view];

    //inexplicably to me, this logs 0.0 instead of 320 on the iphone5:
    DLog(@"actual starting x position: %f", self.currentViewController.view.frame.origin.x);


    [UIView animateWithDuration:kDefaultAnimationTime
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{self.currentViewController.view.frame = self.viewContainer.bounds;}
                     completion:^(BOOL finished){
                         //
                     }];
}
4

0 回答 0