removeFromSuperview包含动画和视图管理

时间:2011-07-26 17:07:34

标签: iphone objective-c uiview view uitabbarcontroller

我做了一些关于这方面的事情,但似乎没有什么能回答我的特定问题(甚至没有:Is it possbile to removeFromSuperview with Animation?)。

基本上,我的应用程序以欢迎屏幕开始,用户点击“登录”,然后转到登录视图,然后转到标签栏视图,这是实际的应用程序。

我这样做的方法是,我编写了一个自定义类 - TabBarController,它设置了所有选项卡及其各自的视图控制器。现在,当用户点击“登录”时,我正在调用removeFromSuperview并显示标签栏。

我正在尝试找到一种方法来设置从登录页面到标签栏的转换动画。我在这里尝试了一些提议的解决方案,但似乎都没有做到这一点。这是我在signin.m视图控制器中的代码。我希望为当前视图制作动画(理想情况下,不仅仅是淡出,还有更多很酷的东西,比如翻转等)。

//when done signing in --> go to the tab bar view 
-(IBAction)done:(id)sender {

TabBarController  *tabController = [[TabBarController alloc] init];
[UIView beginAnimations:@"removeWithEffect" context:nil];
[UIView setAnimationDuration:4.0];
self.parentViewController.view.frame = CGRectMake(0,0,320,480);
self.parentViewController.view.alpha = 1.0f;
[UIView commitAnimations];
[self.parentViewController.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.5f];
[self presentModalViewController:tabController animated:YES];

}

感谢任何帮助!

2 个答案:

答案 0 :(得分:11)

那不可能那样。 presentModalViewController在自己的视图上展开viewController的视图。它不会替换源viewController(self)。 由于您从视图层次结构中删除了self.parentViewController.view,因此您无法以模态方式显示您的tabController,因为您已删除了self。

无论如何,我建议你采用另一种方式来实现你的视图布局: 创建一个tabBarViewController并将其视图添加到rootView(app委托中的self.window或您现在使用的任何内容)。然后将您的登录视图添加到同一视图。由于视图层次结构,登录视图将显示在tabBar.view上方。完成按钮应该以这种方式实现:(我正在使用动态块语法)

-(IBAction)done:(id)sender {
    [UIView animateWithDuration:1.0 
                     animations:^{
                         self.view.frame = CGRectMake(0, 480, 320, 480);
                         self.view.alpha = 0.0
                     } 
                     completion:^(BOOL finished){
                         [self.view removeFromSuperView];
                     }
     ];
}

您可以动画更多内容,而不仅仅是alpha,大小或位置。只需查看documentation中的动画即可。我想,你会对view.transform感兴趣提交翻转动画。 ;)

答案 1 :(得分:1)

这是动画制作后删除视图的方法。

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:myView];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];

[UIView commitAnimations];

希望这会有所帮助。 快乐的编码。