2010-02-19 21 views

Respuesta

1

La rueda giratoria es definitivamente un UIActivityIndicatorView. El texto "Cargando ..." es un UILabel, el rectángulo podría ser una imagen o podría ser una UIView con esquinas redondeadas (a través de CALayer). ¿Alguna pregunta sobre el resto del mensaje? T

1

Si está buscando soluciones existentes puede usar la biblioteca three20 - han implementado esta funcionalidad en la clase TTActivityLabel.

22

Algo similar a lo siguiente en su initWithFrame de su encargo UIView subclase:

_hudView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 170, 170)]; 
    _hudView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; 
    _hudView.clipsToBounds = YES; 
    _hudView.layer.cornerRadius = 10.0; 

    _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    _activityIndicatorView.frame = CGRectMake(65, 40, _activityIndicatorView.bounds.size.width, _activityIndicatorView.bounds.size.height); 
    [_hudView addSubview:_activityIndicatorView]; 
    [_activityIndicatorView startAnimating]; 

    _captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)]; 
    _captionLabel.backgroundColor = [UIColor clearColor]; 
    _captionLabel.textColor = [UIColor whiteColor]; 
    _captionLabel.adjustsFontSizeToFitWidth = YES; 
    _captionLabel.textAlignment = NSTextAlignmentCenter; 
    _captionLabel.text = @"Loading..."; 
    [_hudView addSubview:_captionLabel]; 

    [self addSubview:_hudView]; 
+0

Awesome! ¡Gracias por la solución! –

0

Mi forma de hacer esto funciona mucho más simple y suave para mí;

El diseño de su visión de carga en el Interface Builder dentro de su "MainWindow.xib" que está disponible durante todo el tiempo de vida de la aplicación (por supuesto, si usted tiene uno, dependiendo del tipo y estructura de elección) Si no tiene uno, simplemente diseñe dentro de una vista donde puede agarrar un puntero desde su AppDelegate principal (use su gusto de elección de diseño, pero usando MainWindow.xib es el más fácil)

Luego asigne esta vista a una variable en su clase YourApp, que es la infame clase de delegados de su aplicación.

Let the designed View map to an IBOutlet named "loading" 
inside your app delegate class "YourApp" 
by using the Interface Builder's wiring 

Luego, se coloca las siguientes funciones de alguna clase y ellos disfrutan de

Esto muestra la vista de la carga justo antes de ejecutar algunas cosas caras;

+(void)showLoading { 
    YourApp* app = (YourApp*)[[UIApplication sharedApplication] delegate]; 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = true; 
    [app.loading removeFromSuperview]; 
    [app.window addSubview:app.loading]; 
    app.loading.alpha = 0.0; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.50]; 
    app.loading.alpha = 0.8; 
    [UIView commitAnimations]; 
} 

y esto para sacarlo de la devolución de llamada o lo que pasa cuando se completa la acción costosa;

+(void)hideLoading { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = false; 
    YourApp* app = (YourApp*)[[UIApplication sharedApplication] delegate]; 
    [app.loading removeFromSuperview]; 
} 

PD: Y sí utilizo NULL, verdadero, falso en lugar de cero, sí, no por razones obvias ...

creo que sirve, Disfruta ...

1

ven esto ----

- (void)viewDidLoad { 
    [super viewDidLoad]; 

     // [self ShowMsg]; 

    //-----------------checking version of IOS ----------------------------------- 
    CGFloat ver = [[[UIDevice currentDevice]systemVersion]floatValue]; 
    NSString *str = [NSString stringWithFormat:@"%f",ver]; 
    NSLog(@"%@",str); 
    NSArray *arr = [str componentsSeparatedByString:@"."]; 
    strVerChk = [arr objectAtIndex:0]; 
    NSLog(@"%@",strVerChk); 
    [strVerChk retain]; 

    NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
    NSLog(@"integer %d",verChk); 
    if (verChk < 5) { 
     imag = [UIImage imageNamed:@"WaitScreen.png"]; 
    } 
    else 
    { 
     imag = [UIImage imageNamed:@"WaitScreen_5.png"]; 
    } 
    Lblmsg = [[UILabel alloc]init]; 
       //WithFrame:CGRectMake(10, 10, 100, 30)]; 
    Lblmsg.backgroundColor = [UIColor clearColor]; 
    Lblmsg.textColor = [UIColor whiteColor]; 
    Lblmsg.text = @"  Please Wait...."; 

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     [Lblmsg setFont:[UIFont fontWithName:@"Arial" size:16]]; 
    }else 
    { 
     [Lblmsg setFont:[UIFont fontWithName:@"Arial" size:12]]; 
    } 

    Lblmsg.textAlignment = UITextAlignmentCenter; 
    activityInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    // [activityInd startAnimating]; 

    imageview = [[UIImageView alloc]initWithImage:imag]; 
    [imageview addSubview:Lblmsg]; 
    [imageview addSubview:activityInd]; 
    [self.view addSubview:imageview]; 
    self.view.backgroundColor = [UIColor clearColor]; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 

     // self.interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation 
     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
     if(orientation == UIInterfaceOrientationPortrait ||orientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 
      self.view.frame = CGRectMake(0, 0, 320, 480); 
      imageview.frame = CGRectMake(100, 130, 120, 80); 
     } 
     else{ 
      self.view.frame = CGRectMake(0, 0, 480, 320); 
      imageview.frame = CGRectMake(180, 70, 120, 80); 

     } 
     Lblmsg.frame = CGRectMake(0, 45, 120, 40); 

     NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
     NSLog(@"integer %d",verChk); 
     if (verChk < 5) { 
      activityInd.frame = CGRectMake(41, 9, 28, 28); 
     } 
     else 
     { 
      activityInd.frame = CGRectMake(41, 9, 28, 28); 
     } 
     [activityInd startAnimating]; 
    } 
    else{ 

     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
     if(orientation == UIInterfaceOrientationPortrait ||orientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 
      self.view.frame = CGRectMake(0, 0, 768, 1024); 
      imageview.frame = CGRectMake(274, 330, 210, 160); 
      Lblmsg.frame = CGRectMake(10, 115, 190, 30); 
      NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
      NSLog(@"integer %d",verChk); 
      if (verChk < 5) {   
      activityInd.frame = CGRectMake(71, 20, 52, 52); 
      } 
      else 
      { 
       activityInd.frame = CGRectMake(71, 20, 49, 49); 
      } 
      [activityInd startAnimating]; 

     } 
     else{ 
      self.view.frame = CGRectMake(0, 0, 1024, 768); 
      imageview.frame = CGRectMake(390, 264, 200, 150); 
      Lblmsg.frame = CGRectMake(10, 115, 180, 30); 

      NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
      NSLog(@"integer %d",verChk); 
      if (verChk < 5) {   
       activityInd.frame = CGRectMake(68, 17, 52, 52); 
      } 
      else 
      { 
       activityInd.frame = CGRectMake(68, 17, 49, 49); 
      } 
      [activityInd startAnimating]; 

     } 


    } 


    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(didRotate) 
               name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

} 
-(void)didRotate{ 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 

     // self.interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation 
     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
     if(orientation == UIInterfaceOrientationPortrait ||orientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 
      self.view.frame = CGRectMake(0, 0, 320, 480); 
      imageview.frame = CGRectMake(100, 130, 120, 80); 
      //Lblmsg.frame = CGRectMake(0, 40, 120, 30); 
      //activityInd.frame = CGRectMake(20, 10, 80, 30); 


     } 
     else{ 
      self.view.frame = CGRectMake(0, 0, 480, 320); 
      imageview.frame = CGRectMake(180, 70, 120, 80); 

      //activityInd.frame = CGRectMake(20, 10, 80, 30); 
      //activityInd.frame = CGRectMake(50, 15, 10, 10); 
      //[activityInd startAnimating]; 


     } 
     Lblmsg.frame = CGRectMake(0, 45, 120, 40); 
     NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
     NSLog(@"integer %d",verChk); 
     if (verChk < 5) { 
      activityInd.frame = CGRectMake(41, 9, 28, 28); 
     } 
     else 
     { 
      activityInd.frame = CGRectMake(41, 9, 28, 28); 
     } 

     [activityInd startAnimating]; 
    } 
    else{ 

     UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
     if(orientation == UIInterfaceOrientationPortrait ||orientation == UIInterfaceOrientationPortraitUpsideDown) 
     { 
      self.view.frame = CGRectMake(0, 0, 768, 1024); 
      imageview.frame = CGRectMake(274, 330, 210, 160); 
      Lblmsg.frame = CGRectMake(10, 115, 190, 30); 
      NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
      NSLog(@"integer %d",verChk); 
      if (verChk < 5) {   
       activityInd.frame = CGRectMake(71, 20, 52, 52); 
      } 
      else 
      { 
       activityInd.frame = CGRectMake(71, 20, 49, 49); 
      } 
      [activityInd startAnimating]; 


     } 
     else{ 
      self.view.frame = CGRectMake(0, 0, 1024, 768); 
      imageview.frame = CGRectMake(390, 264, 200, 150); 
      Lblmsg.frame = CGRectMake(10, 115, 180, 30); 
      NSInteger verChk = [[NSString stringWithFormat:@"%@",strVerChk]intValue]; 
      NSLog(@"integer %d",verChk); 
      if (verChk < 5) {   
       activityInd.frame = CGRectMake(68, 17, 52, 52); 
      } 
      else 
      { 
       activityInd.frame = CGRectMake(68, 17, 49, 49); 
      } 
      [activityInd startAnimating]; 


     } 


    } 


} 
+0

Gracias, me salvaste el día. –

0

Si quería una animación diferente, he creado una costumbre UIView (Loader Animation) a la que se podía cargar en una subclase de UIActivity.

Cuestiones relacionadas