Objective
UIView not like UIButton plus click events will have a click effect, the experience is much worse, here through customization and expansion to achieve similar uibutton effect.
Body
First, add click event for UIView
Extension UIView {
func addonclicklistener (Target:anyobject, action:selector) {Let
gr = UITapGestureRecognizer (Target:target, action:action)
gr.numberoftapsrequired = 1
userinteractionenabled = True
Addgesturerecognizer (gr)
}
}
Second, add click Effect for UIView
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 () c7/>})
}
override func touchesended (touches:set<uitouch>, withevent event:uievent?) {
uiview.animatewithduration (0.15, animations: {()-> Void in
self.backgroundcolor = Uicolor.clearcolor ( )
})
}
}
Here everyone can change their own click effect, if it is Uiimageview can be changed to click Change Transparency.