2016-05-15 15 views
0

我是使用單獨線程的新手。我想我做錯了。我試圖讓這個動畫發生,但允許用戶在頁面發生時與頁面交互。即使在單獨的線程上,Swift無法與頁面交互

這裏是我的代碼

let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT 
    dispatch_async(dispatch_get_global_queue(priority, 0)) { 
     UIView.animateWithDuration(3.0, animations: { 
      self.backgroundView.layer.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0).CGColor 
     }) 

     dispatch_async(dispatch_get_main_queue()) { 
      self.backgroundView.layer.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0).CGColor 
     } 
    } 
+4

動畫必須發生在主線程上。如果您想允許用戶交互,請使用'animationWithDuration:delay:options:animations:completions:'中的'.AllowUserInteraction'選項。 – Rob

+0

謝謝!成功了! – RubberDucky4444

回答

0

謝謝@Rob的答案。

動畫必須發生在主線程上。如果要允許用戶交互,請使用animationWithDuration中的.AllowUserInteraction選項:延遲:選項:動畫:完成

相關問題