【问题标题】:UIActivityIndicatorView or similarUIActivityIndi​​catorView 或类似的
【发布时间】:2010-02-19 14:38:31
【问题描述】:


(来源:tumblr.com

谁能告诉我如何实现这样的加载信息?它是 UIActivityIndi​​catorView 的一些变体吗? 谢谢 彼得

【问题讨论】:

  • 什么配色方案...

标签: iphone uiactivityindicatorview


【解决方案1】:

在您的自定义子类 UIView 的 initWithFrame 中类似于以下内容:

    _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];

【讨论】:

  • 太棒了!感谢您的解决方案!
【解决方案2】:

纺车绝对是一个UIActivityIndi​​catorView。 “正在加载...”文本是 UILabel,矩形可以是图像,也可以是带有圆角的 UIView(通过 CALayer)。对邮件的其余部分有任何疑问吗? T

【讨论】:

    【解决方案3】:

    如果您正在寻找现有的解决方案,您可以使用 three20 库 - 他们已在 TTActivityLabel 类中实现了此功能。

    【讨论】:

      【解决方案4】:

      看到这个----

      - (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];
      
      
              }
      
      
          }
      
      
      }
      

      【讨论】:

        【解决方案5】:

        我的做法对我来说更简单、更流畅;

        在“MainWindow.xib”内的 Interface Builder 中设计加载视图 在应用程序的整个生命周期中都可用 (当然如果你有的话,取决于选择的类型和结构) 如果您没有,只需在某个视图中设计它,您可以在其中以编程方式从主 AppDelegate 中获取指针(使用您的设计选择,但使用 MainWindow.xib 是最简单的)

        然后将此视图映射到 YourApp 类中的一个变量,该变量是你臭名昭著的应用委托类。

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

        然后,将以下函数放入某个类中并享受它们

        这用于在运行一些昂贵的东西之前显示加载视图;

        +(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];
        }
        

        然后将其从回调中删除,或者在完成昂贵的操作时将其从回调中删除;

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

        P.S: 是的,我使用 NULL,true,false 代替 nil,YES,NO 出于显而易见的原因......

        希望对你有帮助, 享受...

        【讨论】:

          【解决方案6】:

          如果您想要不同的动画,我创建了一个自定义 UIView (Loader Animation),您可以将其加载到 UIActivity 的子类中。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-01-09
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多