2012-02-22 73 views
8

可能重复:
Show activity indicator during application launch添加活动指示灯编程到View

所有,

在我的应用程序的委托,我创建了一个使用我的默认的动画闪图巴纽。这一切工作正常,但我不知道如何让我的ActivityIndi​​cator显示在飞溅视图的顶部。它只是在飞溅视图中隐藏。以下是我已经和感谢:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
//... data access stuff here ... 

self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

// ... more setup stuff here ... 



/**************************************************************************** 
* 
* 
* Splash Screen for iPhone 
* 
****************************************************************************/ 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 


    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; 
    splashView.image = [UIImage imageNamed:@"Default.png"]; 
    [self.window addSubview:splashView]; 
    [self.window bringSubviewToFront:splashView]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
    splashView.alpha = 0.0; 
    splashView.frame = CGRectMake(-60, -60, 440, 600); 
    [UIView commitAnimations]; 


    //Create and add the Activity Indicator to splashView 
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    activityIndicator.alpha = 1.0; 
    activityIndicator.center = CGPointMake(160, 240); 
    activityIndicator.hidesWhenStopped = NO; 
    [splashView addSubview:activityIndicator]; 
    [activityIndicator startAnimating]; 



} 


    return YES; 
} 

回答

22

所有这些谁需要这个,我知道有很多...
(产地上的Xcode 4.2.1版)

所以...

在AppDelegate.h补充一点:

@property (nonatomic, strong) UIImageView *splashView; 

在AppDelegate.m中添加:

在cours页面的顶部@synthesize splashView;
然后:

- (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 setAnimationDelay:2.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
    splashView.alpha = 0.0; 
    [UIView commitAnimations]; 

    //Create and add the Activity Indicator to splashView 
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
    activityIndicator.alpha = 1.0; 
    activityIndicator.center = CGPointMake(160, 360); 
    activityIndicator.hidesWhenStopped = NO; 
    [splashView addSubview:activityIndicator]; 
    [activityIndicator startAnimating]; 
} 

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

[UIView的setAnimationDelay:2.5]负责splashView有多长在前面由您选择的延迟时间。

可以通过改变x/y的所述nubmers在改变指示器的位置:
activityIndi​​cator.center = CGPointMake(160,360);

最后,梅索德下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

只需补充一点:

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

而且你去那里:)
希望它帮助。

有一个很好的编程....

+0

嗨(void)startupAnimationDone:(NSString *)animationID中的参数应该完成:(NSNumber *)完成上下文:(void *)context – morroko 2014-11-14 10:52:38

+0

hidesWhenStopped = NO对我来说是关键,否则无论如何它都会隐藏起来 – noobular 2015-04-22 23:00:17

0

看来你隐藏(阿尔法 - > 0.0)你在0.5秒splashView。在这种情况下你应该看到什么?

+0

是的,这只是给了我一个从splashView到主视图很好的过渡。当我注释掉它时,我仍然得到相同的结果 - ActivityIndi​​cator隐藏在splashView – Slinky 2012-02-22 18:57:22

0

你试过:

[splashView bringSubviewToFront:activityIndicator]; 
+0

后面。获得相同的结果。问题可能是splashView是一个UIImageView。我听说有时把subViews放在UIImageViews顶部不起作用 – Slinky 2012-02-22 18:56:22