【问题标题】:Animation code stopped working动画代码停止工作
【发布时间】:2011-11-28 09:11:42
【问题描述】:

我的 AppDelegate 文件中有动画代码,它使 Default.png 闪屏消失 到应用程序的第一个控制器。 由于我在代码中实现了 TabBar,因此动画停止工作。 知道为什么吗?

- (void) splashFade
{
  splashView = [[UIImageView alloc] 
                initWithFrame:CGRectMake(0,0, 320, 480)];
  splashView.image = [UIImage imageNamed:@"Default.png"];
  [_window addSubview:splashView];
  [_window bringSubviewToFront:splashView];
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:2.0];
  [UIView 
    setAnimationTransition:UIViewAnimationTransitionNone 
    forView:_window cache:YES];
  [UIView setAnimationDelegate:self]; 
  [UIView 
    setAnimationDidStopSelector:
    @selector(startupAnimationDone:finished:context:)];
  splashView.alpha = 0.0;
  [UIView commitAnimations];
}

- (void)startupAnimationDone:(NSString *)animationID 
                finished:(NSNumber *)finished 
                 context:(void *)context
{
  [splashView removeFromSuperview];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  sleep(2);

  [self splashFade];

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  // Override point for customization after application launch.

  UIViewController *viewController1 = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
  UIViewController *viewController2 = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];

  self.tabBarController = [[UITabBarController alloc] init];
  self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
  self.window.rootViewController = self.tabBarController;

  [self.window addSubview:self.rootViewController.view];
  [self.window addSubview:self.navigationController.view];
  [self.window makeKeyAndVisible];

  return YES;
}

【问题讨论】:

    标签: xcode animation tabbar splash-screen


    【解决方案1】:

    尝试使用

    [self performSelector:@selector(splashFade) withObject:nil afterDelay:2];
    

    优于sleep(2)

    【讨论】:

    • Alex 可以正常工作,但发生了一些连线事件。 Default.png 显示,之后 - rootview 控制器像往常一样显示,没有淡出,就在动画开始之后。我的意思是它重复它自己两次。一次不褪色,第二次褪色。你能想到为什么吗?我注意到如果我删除 this:afterDelay:2 淡出根本不起作用。
    • 我做到了:)。需要把它放在 didFinish 的底部(感谢 Kjuly)这是正确的方法: sleep(1.8); [self performSelector:@selector(splashFade) withObject:nil];返回是;
    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 2014-01-20
    • 2012-05-23
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多