簡體   English   中英

點擊動畫的手勢延遲

[英]Tap gesture delay with animation

我有幾個UIView擴展,可以從輕擊手勢識別器中調用。 為什么背景色擴展必須完成動畫處理才能識別出其他拍子? Alpha擴展名加上我用來為視圖工作位置設置動畫的另一個擴展名就很好-這意味着我可以根據需要快速點擊並立即響應。

@IBAction func taps(sender: UITapGestureRecognizer) {
   if !isAnimating {
      currentLabel.fadeOut()
      backgroundColor.fadeBackgroundOut()
      isAnimating = true   
   } else {
      currentLabel.fadeIn()
      backgroundColor.fadeBackgroundIn(curBackground)
      isAnimating = false
   }
}

func fadeOut() {
   UIView.animateWithDuration(0.5,
      delay: 0.0,
      options: UIViewAnimationOptions.CurveEaseOut,
      animations: { self.alpha = 0.0 },
      completion: nil)
}

func fadeBackgroundIn(aColor: UIColor) {
   UIView.animateWithDuration(1.0,
      delay: 0,
      options: UIViewAnimationOptions.CurveEaseIn,
      animations: { self.backgroundColor = aColor },
      completion: nil)
}

將擴展名更新為:

func fadeOut() {
   UIView.animateWithDuration(0.5,
      delay: 0.0,
      options: [UIViewAnimationOptions.CurveEaseIn , UIViewAnimationOptions.AllowUserInteraction],
      animations: { self.alpha = 0.0 },
      completion: nil)
}

func fadeBackgroundIn(aColor: UIColor) {
    UIView.animateWithDuration(1.0,
        delay: 0,
        options: [UIViewAnimationOptions.CurveEaseIn , UIViewAnimationOptions.AllowUserInteraction],
        animations: { self.backgroundColor = aColor },
        completion: nil)
}

這是很容易的事情,您必須了解是否將“自我”的alpha值更改為零,即查看為零,它將停止獲取觸摸事件。

最好的解決方案是將“自身”(即視圖的背景顏色)更改為透明,而不是更改“自身”(即視圖的Alpha值),因為這樣您的視圖將不可見並且會收到手勢識別器事件。

替代解決方案可以是,要在視圖上添加透明按鈕,請處理按鈕輕擊動作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM