Hide activity indicator

2019-02-22 12:58发布

so in my main storyboard i created a Activity Indicator.

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

Here is my code, when i press the button the activity indicator starts animatig.

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

So the question again, can i hide the activity indicator until the button has been pressed and then it will show this activity indicator.

4条回答
beautiful°
2楼-- · 2019-02-22 13:31

Swift 3 Xcode 8.3.2

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

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

Later when you want to show activityIndicator :

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

And when you want to stop it use :

self.activityIndicator.stopAnimating()
查看更多
混吃等死
3楼-- · 2019-02-22 13:37

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.

查看更多
可以哭但决不认输i
4楼-- · 2019-02-22 13:41

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

查看更多
我只想做你的唯一
5楼-- · 2019-02-22 13:50

You can add

self.indicator.hidden = YES;

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

查看更多
登录 后发表回答