0

我有代码:

ListViewController * listViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];    

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self viewWillDisappear:YES];
[listViewController viewWillAppear:YES];

self.view.hidden = YES;
listViewController.view.hidden = NO;


[self viewDidDisappear:YES];
[listViewController viewDidAppear:YES];
[UIView commitAnimations];    

但是它不起作用,并且 listViewController 不显示(请,有人可以告诉我这个问题的解决方案吗?

4

3 回答 3

0

删除不必要的代码,然后写这个......

ListViewController * listViewController = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];    
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.view addSubview:listViewController.view];
[UIView commitAnimations];
于 2012-07-30T13:39:24.377 回答
0

尝试类似:

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 所说,Apple 不鼓励在较新的 iOS 版本中使用基于非块的动画。上述方法是“批准”的方法。

请注意viewWillAppearviewDidDisappear, 和类似的方法不是您调用来使视图执行操作的方法。当这些事情发生时,它们会被自动调用。

您的代码有一些误解;我在下面评论了他们

//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]; 
于 2012-07-30T13:42:00.500 回答
0

它不能工作!

您只需创建和分配一个 UIViewController,但永远不要将其推送到任何堆栈上,或将其视图添加到可见视图。

当您将 listViewController.view.hidden 设置为 no 时,您不会神奇地在屏幕上显示它:您需要将其视图添加到已经在屏幕上的视图(或窗口)中......

ps beginAnimation 已弃用:改用块动画...

于 2012-07-30T13:53:11.917 回答