- (IBAction)StartGame:(id)sender
{
MainGameDisplay *secondPage = [[MainGameDisplay alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:secondPage.view];
secondPage.view.frame = CGRectMake(568, 0, 568, 320);//(N = horizontal, N = vertical)
[UIView animateWithDuration:1.0f
animations:^{
//actual frame needed with an animation.
secondPage.view.frame = CGRectMake(0, 0, 568, 320);
}
completion:^(BOOL finished) {
//ENTER HERE ANYTHING TO RUN AFTER ANIMATION IS COMPLETED:
[self presentViewController: secondPage animated:NO completion:NULL];
//This will make the next page load correctly after the transition, otherwise you cannot. interact with anything.
}];
}
这非常适合进入视图。没有[self presentViewController: secondPage animated:NO completion:NULL];
,您将无法与新页面进行交互,您单击的任何按钮都会导致它崩溃。
如果我返回第一页,正常执行,那很好,但如果我再次单击 StartGame,程序会更改视图,然后简单地崩溃。问题在于行[self.view addSubview:secondPage.view];
,如果我将其注释掉,程序不会崩溃,但是当它更改视图时它不会转换并立即出现。
横向模式下的过渡也非常滞后/故障,但纵向完美。