Reputation: 8376
I have a programatically created UILabel that uses autolayout inside a UIView, inside a UIScrollView. Initially it is off-screen and then slides onto screen (by animating the change of the autolayout constraint constants). I am trying to add a gesture recognizer (single tap) to the UILabel but the gesture never gets recognized. If I add one to the UIView, the gesture recognizer works. Does anyone know what the solution to this would be? Is this a problem caused by autolayout? Thanks.
EDIT
This is definitely to do with the scrollview swallowing touches. I've just created the same label outside of the scrollview and the gesture recogniser works fine!
EDIT 2 I can create the label within the scroll view using Interface Builder, but programmatically it doesn't work...
Upvotes: 0
Views: 1058
Reputation: 8376
Turns out the label was embedded within 2 views, within the view in the scrollview. Taking it out of this seemed to solve them problem...
Upvotes: 0
Reputation: 999
You have to check User Interaction Enabled
in the UILabel
If you are adding a UITapGestureRecognizer programmatically:
In viewDidLoad
i added the following code:
let gesture = UITapGestureRecognizer(target: self, action: Selector("myaction"))
self.label.addGestureRecognizer(gesture)
with the selector:
func myaction() {
println("Label tapped")
}
where self.label
is the reference outlet of the label being tapped.
Upvotes: 1