单击UIButton:iOS Objective C时隐藏默认加载微调器

时间:2017-08-05 06:16:46

标签: ios objective-c iphone

在iOS中运行应用程序时,当我们单击任何按钮(UIButton)时,默认的加载微调器会在屏幕中心旋转,直到执行操作。但是,我不希望加载微调器弹出,而是我想要一个自定义指示器在另一个位置旋转。 我在这里使用UIActivityIndi​​cator,自定义指标在其位置正常工作。但是中心的默认微调器仍在点击时出现。 请建议正确的方法,以便隐藏默认加载微调器或在按钮单击时不弹出。

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame= CGRectMake(textView.frame.size.width+30, 
containerView.frame.size.height-45,40,40);
indicator.autoresizingMask=UIViewAutoresizingFlexibleTopMargin | 
UIViewAutoresizingFlexibleRightMargin;
[containerView addSubview:indicator];
indicator.backgroundColor = [UIColor clearColor];
[indicator startAnimating];
.
.
.

执行按钮操作后..

[indicator stopAnimating];

2 个答案:

答案 0 :(得分:0)

试试这个:

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame= CGRectMake(textView.frame.size.width+30, 
containerView.frame.size.height-45,40,40);
indicator.autoresizingMask=UIViewAutoresizingFlexibleTopMargin | 
UIViewAutoresizingFlexibleRightMargin;
[indicator setHidesWhenStopped:YES]; // i added this 
[containerView addSubview:indicator];
indicator.backgroundColor = [UIColor clearColor];
[indicator startAnimating];

答案 1 :(得分:0)

每次调用此代码时,您的代码都会继续添加新的UIActivityIndi​​catorView。最终,您将拥有隐藏在视图中的100s UIActivityIndi​​cator。你应该做的是将指标声明为属性,并仅在它为零时创建它。

@property (nonatomic, strong) UIActivityIndicatorView *indicator;

-(void)showProcessing {
    if (_indicator==nil)  // here checks for existing indicator in memory
      _indicator = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicator.frame= CGRectMake(textView.frame.size.width+30, 
    containerView.frame.size.height-45,40,40);
    indicator.autoresizingMask=UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleRightMargin;
    [_indicator setHidesWhenStopped:YES];
    [containerView addSubview:_indicator];
    indicator.backgroundColor = [UIColor clearColor];
    [indicator startAnimating];
}

隐藏:

-(void)hideProcessing {
  [_indicator stopAnimating];
}