试着这么做:
UIViewAnimationOptions ops = UIViewAnimationOptionTransitionFlipFromRight;
NSArray *temp = [[NSBundle mainBundle] loadNibNamed:@"NameOfNib" owner:self options:nil];
UIView* newView = [[temp objectAtIndex:0] view];
[UIView transitionFromView:self.view toView:newView duration:1.5 options:ops completion:nil];
self.view = newView; //Lets you control the new view from the current controller (you might want to save a reference to the old one if you need to change back)
正如meronix所说,苹果公司不鼓励非基于块的动画用于较新的iOS版本。上述方法是“批准”的方式。
就这么你知道,viewWillAppear
,viewDidDisappear
和类似的方法不是你调用来使视图做事情的方法。发生这些事情时会自动调用它们。
你的代码有一些误解;我在下面评论过他们
//This looks fine (depending on what is in the nib)
ListViewController * listViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
//Normally I use these to move things around, not change the view
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self viewWillDisappear:YES]; //These two methods aren't things that you call
[listViewController viewWillAppear:YES];
self.view.hidden = YES; //If you're flipping or otherwise moving a view out of
listViewController.view.hidden = NO; //sight then you don't need to hide/unhide views
[self viewDidDisappear:YES]; //Same as above, you don't call these
[listViewController viewDidAppear:YES];
[UIView commitAnimations];
感谢您的澄清!!)我仍然在解决这个问题)我是新的objective-c(( – rubik 2012-07-30 14:04:48
)如果你需要一些教程,请查阅http://www.raywenderlich.com/。几乎所有人都强烈推荐它们。 – Dustin 2012-07-30 14:06:44
感谢您的链接!) – rubik 2012-07-30 14:13:45