iphone5上子视图控制器的视图帧的奇怪行为

时间:2013-05-09 15:42:55

标签: ios uiview uiviewcontroller iphone-5 childviewcontroller

我要做的是创建一个视图控制器,并从右侧对其视图进行动画处理。主视图控制器有一个名为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){
                         //
                     }];
}

0 个答案:

没有答案