swift中,除了条形进度条,还有环形进度条,俗称“菊花”,效果如下图
1,创建
var activityIndicator:UIActivityIndicatorView!
func creatActivity(){ activityIndicator = UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.gray) activityIndicator.center = self.view.center self.view.addSubview(activityIndicator) //开发触发 play() }
func play(){ //进度条开始转动 activityIndicator.startAnimating() } func stop() { //进度条停止转动 activityIndicator.stopAnimating() }
2,判断点击屏幕一下,停止菊花,具体代码如下:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch:AnyObject in touches { let t:UITouch = touch as! UITouch //当在屏幕上拍动一下时,终止环形进度条 if t.tapCount == 1{ self.stop() } }
结束!