Created
June 20, 2016 10:19
-
-
Save oksep/32ea6a6bcd37bd74b2614099d63f1aae to your computer and use it in GitHub Desktop.
iOS UIView custom interaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
func addOnClickListener(target: AnyObject, action: Selector) { | |
let gr = UITapGestureRecognizer(target: target, action: action) | |
gr.numberOfTapsRequired = 1 | |
userInteractionEnabled = true | |
addGestureRecognizer(gr) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIViewEffect : UIView { | |
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { | |
backgroundColor = UIColor.groupTableViewBackgroundColor() | |
} | |
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) { | |
UIView.animateWithDuration(0.15, animations: { () -> Void in | |
self.backgroundColor = UIColor.clearColor() | |
}) | |
} | |
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { | |
UIView.animateWithDuration(0.15, animations: { () -> Void in | |
self.backgroundColor = UIColor.clearColor() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment