swift 如何实现点击view后显示灰色背景
生活随笔
收集整理的這篇文章主要介紹了
swift 如何实现点击view后显示灰色背景
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
有這樣一種場景,當(dāng)我們點擊view的時候,需要過0.幾秒顯示一個灰色或者別的顏色的背景
用button來實現(xiàn),只有按下去的時候才會出現(xiàn),往往在快速按下,快速抬起的時候是看不出這個變化的
下邊是解決方案
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 }?
轉(zhuǎn)載于:https://www.cnblogs.com/machao/p/5127098.html
總結(jié)
以上是生活随笔為你收集整理的swift 如何实现点击view后显示灰色背景的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蓝懿IOS学习UICollectionV
- 下一篇: Perl中的单行凝视和多行凝视