以编程方式将活动指示器添加到视图中

可能重复:
在应用程序启动时显示活动指示

所有,

在我的应用程序委托中,我创build了一个使用我的Default.png的animation飞溅视图。 这一切工作正常,但我不知道如何让我的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; } 

对于所有需要这些的人,我知道有很多…
(在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]负责在您select的延迟时间内splashView将在前面多久。

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

最后,在方法之下:

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

只需添加这个:

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

在那里你去:)
希望它有帮助。

有一个很好的编程….

似乎你在0.5秒内隐藏(alpha – > 0.0)你的splashView。 在这种情况下你应该看到什么?

你有没有尝试过:

 [splashView bringSubviewToFront:activityIndicator];