日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

swift 如何实现点击view后显示灰色背景

發布時間:2025/7/14 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 swift 如何实现点击view后显示灰色背景 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有這樣一種場景,當我們點擊view的時候,需要過0.幾秒顯示一個灰色或者別的顏色的背景

用button來實現,只有按下去的時候才會出現,往往在快速按下,快速抬起的時候是看不出這個變化的

下邊是解決方案

1 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 2 3 let touch = touches.first! 4 let p = touch.locationInView(self.retweetBackgroundView) 5 let insideRetweet = CGRectContainsPoint(self.retweetBackgroundView!.bounds ,p) 6 7 if self.retweetBackgroundView?.hidden == false && insideRetweet { 8 9 self.retweetBackgroundView!.performSelector("setBackgroundColor:", withObject: kWBCellHighlightColor, afterDelay: 0.15) 10 self._touchRetweetView = true 11 }else { 12 13 self.contentView!.performSelector("setBackgroundColor:", withObject: kWBCellHighlightColor, afterDelay: 0.15) 14 self._touchRetweetView = false 15 } 16 17 } 18 19 override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { 20 21 self.touchesRestoreBackgroundColor() 22 } 23 24 override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) { 25 26 self.touchesRestoreBackgroundColor() 27 } 28 29 func touchesRestoreBackgroundColor() { 30 NSObject.cancelPreviousPerformRequestsWithTarget(self.retweetBackgroundView!, selector: "setBackgroundColor:", object: kWBCellHighlightColor) 31 NSObject.cancelPreviousPerformRequestsWithTarget(self.contentView!, selector: "setBackgroundColor:", object: kWBCellHighlightColor) 32 self.retweetBackgroundView!.backgroundColor = UIColor.whiteColor() 33 self.contentView.backgroundColor = kWBCellInnerViewColor 34 }

?

轉載于:https://www.cnblogs.com/machao/p/5127098.html

總結

以上是生活随笔為你收集整理的swift 如何实现点击view后显示灰色背景的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。