无法显示活动指示器iOS

时间:2014-04-03 11:19:08

标签: ios iphone objective-c

我想在UIActivityIndicator的屏幕上显示viewDidLoad。它在另一个项目中工作,但不确定为什么它不在这里显示。

我从其他屏幕的viewDidLoad调用showSplashScreen。

+(void) showSplashScreen
{
    UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];

    UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
    windowBlocker.tag = 999;
    windowBlocker.backgroundColor = [UIColor clearColor];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
    imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];

    imageView.layer.cornerRadius=10;
    imageView.layer.masksToBounds = YES;
    [windowBlocker addSubview:imageView];

    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [windowBlocker addSubview:spinner];
    spinner.center = mainScreen.center;
    [spinner startAnimating];
}
没有任何反应。任何的想法?我正在尝试iPad。

5 个答案:

答案 0 :(得分:5)

 UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [imageView addSubview:spinner];
    spinner.center = mainScreen.center;
    [windowBlocker addSubview:imageView];
    [self.view addSubview: mainScreen];
    [spinner startAnimating];

答案 1 :(得分:1)

看起来问题是你没有将windowBlocker添加到屏幕上。

尝试:

[mainScreen addSubview:windowBlocker];

答案 2 :(得分:1)

//忘了忘记在主视图中添加windowBlocker

   [Self.view addSubview:windowBlocker];


UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.center = mainScreen.center;
    [spinner startAnimating];
    [windowBlocker addSubview:spinner];

//试试这段代码

答案 3 :(得分:0)

改变这个......它适合你

       UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       spinner.color=[UIColor greenColor];
       spinner.center = self.view.center;
      [spinner startAnimating];
      [windowBlocker addSubview:spinner];

答案 4 :(得分:0)

-(void)viewWillAppear:(BOOL)animated    {
    [super viewWillAppear:animated];
    [self performSelector:@selector(addSplash) withObject:nil afterDelay:0.5];
}

-(void)addSplash    {
    [[self class] showSplashScreen];
}

+(void) showSplashScreen
{
    UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];

    UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
    windowBlocker.tag = 999;
    windowBlocker.backgroundColor = [UIColor redColor];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
    imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];

    imageView.layer.cornerRadius=10;
    imageView.layer.masksToBounds = YES;
    [windowBlocker addSubview:imageView];

    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [windowBlocker addSubview:spinner];
    spinner.center = mainScreen.center;
    [spinner startAnimating];

    [[[[UIApplication sharedApplication]delegate]window] addSubview:windowBlocker];

}

因为我在0.5添加了一些延迟,因为当我在ViewDidLoadViewWillAppear中调用函数时,某些原因导致视图没有意外,因此我提供了一些延迟,或者您可以使用{{1作为此情况的一个选项,仅此功能并删除viewDidAppearviewWillAppear并仅添加此

addSplash