I have a UIView
on top of some other UI components to detect a long-pressed gesture. When a long press begins, I want to tip the user by changing the background color to gray & alpha = 0.1.
After the long press ends, the UIView
has to be changed back as completely transparent. I set its alpha to 0, but the problem is ...
no further guesture can be detected.
mainView = UIView()
mainView.frame = ...
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action:Selector("longPressed:"))
mainView.addGestureRecognizer(longPressRecognizer)
func longPressed(sender: UILongPressGestureRecognizer) {
let view = sender.view!
if sender.state == .Began {
view.backgroundColor = UIColor.grayColor()
view.alpha = 0.1
} else if (sender.state == .Ended || sender.state == .Cancelled || sender.state == .Failed) {
view.backgroundColor = UIColor.whiteColor()
view.alpha = 0
}
}
What's the correct way to make this UIView
changed back to its original state so that further gestures can be detected as it's initially created?
Setting a UIView's alpha
property to 0 will make it stop receiving touches. Instead, set its background to UIColor.clearColor()
when you want it invisible.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.