Objective
UIView not like UIButton added Click event will have a click effect, experience is much worse, here respectively through customization and extension to achieve similar UIButton effect.
Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com
Body
First, add a click event for UIView
extension UIView { func addonclicklistener (Target:anyobject, action:selector) { = UITapGestureRecognizer (Target:target, action:action) 1 true Addgesturerecognizer (GR) }}
Second, add click Effect for UIView
classUivieweffect:uiview {OverrideFunc Touchesbegan (touches:set<uitouch>, witheventEvent: Uievent?) {BackgroundColor=uicolor.grouptableviewbackgroundcolor ()}OverrideFunc touchescancelled (touches:set<uitouch>?, WitheventEvent: Uievent?) {uiview.animatewithduration (0.15, animations: {(), VoidinchSelf.backgroundcolor=Uicolor.clearcolor ()}) } OverrideFunc touchesended (touches:set<uitouch>, witheventEvent: Uievent?) {uiview.animatewithduration (0.15, animations: {(), VoidinchSelf.backgroundcolor=Uicolor.clearcolor ()}) }}
Here everyone can be replaced by their own click effect, if it is Uiimageview can be replaced by click Change Transparency.
"Swift 2.1" adds click events and click Effects for UIView