以编程方式向视图添加活动指示器

Sli*_*nky 8 uiactivityindicatorview uiapplicationdelegate ios

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

所有,

在我的app委托中,我创建了一个使用我的Default.png的动画启动视图.一切正常,但我无法弄清楚如何让我的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;
}
Run Code Online (Sandbox Code Playgroud)

Mao*_*har 22

对于所有需要这个的人,我知道有很多...
(在Xcode版本4.2.1上制作)

所以...

在AppDelegate.h中添加:

@property (nonatomic, strong) UIImageView *splashView;
Run Code Online (Sandbox Code Playgroud)

在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];
}
Run Code Online (Sandbox Code Playgroud)

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

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

最后,根据方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Run Code Online (Sandbox Code Playgroud)

只需添加:

[self performSelector:@selector(splashFade) withObject:nil];
Run Code Online (Sandbox Code Playgroud)

你去吧:)
希望它有所帮助.

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