2012-07-30 98 views
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不显示(请,有人可以告诉我这个问题的解决方案

回答

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所说,苹果公司不鼓励非基于块的动画用于较新的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]; 
+0

感谢您的澄清!!)我仍然在解决这个问题)我是新的objective-c(( – rubik 2012-07-30 14:04:48

+0

)如果你需要一些教程,请查阅http://www.raywenderlich.com/。几乎所有人都强烈推荐它们。 – Dustin 2012-07-30 14:06:44

+0

感谢您的链接!) – rubik 2012-07-30 14:13:45

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]; 
+0

当我使用此代码时,我当前的视图(它的地图视图)只在当场旋转..((我需要将当前视图(IBOutlet MKMapView * map)更改为listView。 – rubik 2012-07-30 13:46:29

+0

它会翻转listViewController.view你可以翻转任何视图,只需将listViewcontroller.view替换为你的视图,因为在你的问题中,你只是要求fliping – TheTiger 2012-07-30 13:51:38

+0

对不起,我的任务中有点不正确的东西离子 – rubik 2012-07-30 13:56:44

0

它不能工作!

您只需创建并分配一个UIViewController,但绝不会将它推到任何堆栈上,或将其视图添加到可见视图中。

当您设置listViewController.view.hidden没有,你是不是神奇地显示它在屏幕上:你需要它的视图添加到视图(或窗口),这已经是在屏幕上......

PS beginAnimation已弃用:使用块动画代替...

+1

'beginAnimations'不被弃用......我认为这只是气馁。 – Dustin 2012-07-30 13:57:08

+0

不,你说得对,苹果只是说:“在iOS 4.0和更高版本中不鼓励使用这种方法,你应该使用基于块的动画方法来指定你的动画。” (推荐)“ – meronix 2012-07-30 13:59:34

+0

好吧,我很担心,因为我的一些旧应用程序使用'beginAnimations',我不想被搞砸通过iOS 6.另外,您会看到我的答案确实推荐了基于块的方法。 – Dustin 2012-07-30 14:03:08

相关问题