【问题标题】:Adding an activityIndicator on modalViewController iphone在modalViewController iphone上添加一个activityIndi​​cator
【发布时间】:2010-07-15 12:53:11
【问题描述】:

我正在尝试在 modalViewController 上添加一个 activityIndi​​cator。

基本上,我想在用户按下此 modalViewController 上的按钮后开始为该 activityIndi​​cator 设置动画。但是发生的事情是我在此 modalViewController 上触发 presentModalViewController 之前所做的任何事情都保持不变,即如果我只是添加 activityIndi​​cator 并在呈现 modalView 之后,那么即使我启动它也不会出现。但是如果在预设这个modalViewController之前如果我触发[activity startAnimating];然后在呈现 modalView 活动后显示动画。

所以基本上,我想简单地在 modalViewController 上添加 activityIndi​​cator 并在按下按钮后开始对其进行动画处理。

我正在使用以下代码:

  imageUploadView = [[UIViewController alloc]initWithNibName:nil bundle:nil]; 
  CGRect frame = CGRectMake(140.0, 410.0, 25.0, 25.0);
  loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
  [loading sizeToFit];
   loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
    UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleTopMargin |
    UIViewAutoresizingFlexibleBottomMargin);

   [imageUploadView.view addSubview:loading];
   [_picker_ presentModalViewController:imageUploadView animated:YES];

有人可以帮忙吗?

提前感谢。

【问题讨论】:

    标签: iphone uiactivityindicatorview modalviewcontroller


    【解决方案1】:

    在您的 ViewController、viewDidLoad 或 ViewWillAppear 中试试这个:

      CGRect frame = CGRectMake(140.0, 410.0, 25.0, 25.0);
      loading = [[[UIActivityIndicatorView alloc] initWithFrame:frame] autoRelease];
      [loading sizeToFit];
      loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
      UIViewAutoresizingFlexibleRightMargin |
      UIViewAutoresizingFlexibleTopMargin |
      UIViewAutoresizingFlexibleBottomMargin);
      [self.view addSubView:loading];
      loading.startAnimateing
    

    【讨论】:

    • 倒数第二行必须是“addSubview”,不能大写“v”。
    【解决方案2】:

    将其添加为子视图。

    【讨论】:

    • 看看你的看法,然后拨打[whatevertheviewis addSubview:anactivityindicatorview];
    【解决方案3】:

    我用下面的代码解决了这个问题

     activityIndicatorObject = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    
     // Set Center Position for ActivityIndicator
    
     activityIndicatorObject.center = CGPointMake(150, 250);
     activityIndicatorObject.backgroundColor=[UIColor grayColor];
    
     // Add ActivityIndicator to your view
     [self.view addSubview:activityIndicatorObject];
    
     activityIndicatorObject.hidesWhenStopped=NO;
    
     [activityIndicatorObject startAnimating];
    

    【讨论】:

      猜你喜欢
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多