[英]animating view change with uitabbarcontroller
我想为我的视图更改设置动画,但是我不确定将我的 animation 放在哪里,因为我有一个 UITabBarController 控制我在哪个视图上以及我也可以切换什么。这是在我的 appdelegate.m 文件中声明的xcode 模板。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
或者它们是每个视图控制器中加载所有内容的区域......我认为在这里初始化 animation 可能会更好。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Super", @"Super");
self.tabBarItem.image = [UIImage imageNamed:@"SuperIcon"];
}
return self;
}
因为我没有做很多 animation 的视图,然后我才可以在哪里声明这段代码,希望在触摸 UITabBarButton 时动画我的视图变化......
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView];
completion:NULL];
还是我完全错过了船,我应该在其他地方做这件事吗?
在 viewWillAppear 方法中尝试以下代码
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];
这对我来说适用于基于 tabBar controller 的应用程序。
在 viewWillAppear 方法的代码中尝试 animation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.