gpt4 book ai didi

iphone - 带有动画和 View 管理的 removeFromSuperview

转载 作者:太空狗 更新时间:2023-10-30 03:57:57 24 4
gpt4 key购买 nike

我对此进行了一些挖掘,但似乎没有什么能真正回答我的特定问题(甚至这个:Is it possbile to removeFromSuperview with Animation?)。

基本上,我的应用程序从一个欢迎屏幕开始,用户点击“登录”,然后进入登录 View ,然后进入标签栏 View ,这是实际的应用程序。

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

我正在尝试找到一种方法来动画化从登录页面到标签栏的过渡。我在这里尝试了一些建议的解决方案,但似乎没有一个能完成这项工作。这是我在 signin.m View Controller 中的代码。我希望为当前 View 添加动画效果(理想情况下,不仅仅是淡出,而是翻转等更酷的东西)。

//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];

}

感谢任何帮助!

最佳答案

那不行。 presentModalViewController 在自己的 View 上显示 viewController 的 View 。它不会替换源 View Controller (自身)。由于您从 View 层次结构中删除了 self.parentViewController.view,因此它无法以模态方式呈现您的 tabController,因为您已删除 self。

无论如何,我会向您推荐另一种实现 View 布局的方法:创建一个 tabBarViewController 并将其 View 添加到 rootView(应用程序委托(delegate)中的 self.window 或您现在使用的任何内容)。然后将您的登录 View 添加到同一 View 。由于 View 层次结构,登录 View 将显示在 tabBar.view 上方。并且完成按钮应该以这种方式实现:(我正在使用动画的 block 语法,因为它应该是)

-(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 提交翻转动画感兴趣。 ;)

关于iphone - 带有动画和 View 管理的 removeFromSuperview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6833835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com