Make UIAlertViewController action unclickable?
我想让
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | @IBOutlet var activityView: UIActivityIndicatorView! var alert = UIAlertController(title: nil, message:"Please wait...", preferredStyle: UIAlertControllerStyle.Alert) override func viewDidLoad(){ self.activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge) self.activityView.center = CGPointMake(130.5, 65.5) self.activityView.color = UIColor.blackColor() } @IBAction func importFiles(sender: AnyObject){ self.alert.view.addSubview(activityView) self.presentViewController(alert, animated: true, completion: nil) alert.addAction(UIAlertAction(title:"Ok", style: UIAlertActionStyle.Default, handler: nil)) //Somehow here I want to make it so that the UIAlertAction is unclickable. self.activityView.startAnimating() } |
一切正常,但我似乎无法找到一种方法让动作只有在动画完成后才能点击。我尝试将操作添加到
一般来说,我建议不要使用警报视图作为此类任务的占位符。但为了给你一个想法,看看这个:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | lazy var alert: UIAlertController = { var alert = UIAlertController(title:"Please wait...", message:"Please wait for some seconds...", preferredStyle: .Alert) alert.addAction(self.action) return alert }() lazy var action: UIAlertAction = { var action = UIAlertAction(title:"Ok", style: .Default, handler: nil) action.enabled = false return action }() override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) self.presentViewController(alert, animated: true, completion: nil) let delayInSeconds = 3.0 let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delayInSeconds * Double(NSEC_PER_SEC))) dispatch_after(popTime, dispatch_get_main_queue()) { () -> Void in self.action.enabled = true } } |
延迟部分在哪里
1 2 3 4 5 | let delayInSeconds = 3.0 let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delayInSeconds * Double(NSEC_PER_SEC))) dispatch_after(popTime, dispatch_get_main_queue()) { () -> Void in self.action.enabled = true } |
应该由你的获取逻辑替换。
祝你好运!