xcode 隐藏活动指示器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28865659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:46:06  来源:igfitidea点击:

Hide activity indicator

iosxcodeuiactivityindicatorview

提问by Student

On my main storyboard I created an Activity Indicator.

在我的主故事板上,我创建了一个活动指示器。

I want to hide my activity indicator until the button has been pressed. Is there a way I can do that?

我想隐藏我的活动指示器,直到按下按钮。有没有办法做到这一点?

When I press the button the activity indicator starts animating.

当我按下按钮时,活动指示器开始动画。

self.indicator.hidden = NO;
[self.indicator startAnimating];
[self performSelector:@selector(showData) withObject:nil afterDelay:2.0f];

Can I hide the activity indicator until the button has been pressed, and then show this activity indicator?

我可以在按下按钮之前隐藏活动指示器,然后显示此活动指示器吗?

回答by Jose Manuel Abarca Rodríguez

Select the Activity Indicator in Storyboard, then select property "Hides when stopped". This way you don't have to hide it, just start or stop the animation, and the Activity Indicator will show and hide automatically. Of course, you still have to add the code to start and stop the animation to buttons.

在 Storyboard 中选择活动指示器,然后选择属性“停止时隐藏”。这样您就不必隐藏它,只需启动或停止动画,Activity Indicator 就会自动显示和隐藏。当然,您仍然需要添加代码来启动和停止按钮的动画。

storyboard

故事板

回答by Prashant Gaikwad

Swift 3 Xcode 8.3.2

斯威夫特 3 Xcode 8.3.2

First hide your activityIndicator in viewDidLoad() method and set hidesWhenStopped property to true.

首先在 viewDidLoad() 方法中隐藏您的 activityIndi​​cator 并将 hidesWhenStopped 属性设置为 true。

override func viewDidLoad(){
     super.viewDidLoad()
     self.activityIndicator.isHidden = true
     self.activityIndicator.hidesWhenStopped = true
}

Later when you want to show activityIndicator :

稍后当您想显示 activityIndi​​cator 时:

self.activityIndicator.isHidden = false
self.activityIndicator.startAnimating()

And when you want to stop it use :

当您想停止它时,请使用:

self.activityIndicator.stopAnimating()

回答by Natasha

if you are using swift then you can do it when you set the outlet of your indicator, like-

如果您使用的是 swift,那么您可以在设置指示器的出口时执行此操作,例如-

@IBOutlet weak var indicator:UIActivityIndicatorView!{
     didSet{
          indicator.hidesWhenStopped = true
     }
}

Basically what it meant is, set my activity indicator outlet's hidesWhenStopped property to true when it is established.

基本上它的意思是,在建立我的活动指示器插座的 hidesWhenStopped 属性时将其设置为 true。

回答by Bartosz Bialecki

Yes, you can select Hidden property in the Storyboard, and change it in your button action method when you tap it. But you can just select Hides when Stopped and your activity will be hidden if not animating and show up otherwise.

是的,您可以在 Storyboard 中选择 Hidden 属性,然后在点击它时在按钮操作方法中更改它。但是您可以选择停止时隐藏,如果没有动画,您的活动将被隐藏,否则会显示。

回答by Avt

You can add

你可以加

self.indicator.hidden = YES;

to your UIViewController's viewDidLoad method or select Hidden checkmark in Storyboard.

到您的 UIViewController 的 viewDidLoad 方法或在 Storyboard 中选择隐藏的复选标记。