UITapGestureRecognizer not working on UILabel but working on parent view
up vote
1
down vote
favorite
View hierarchy is like this,
- control (UIView)
- container (UIView)
- icon (UILabel)
- label(UILabel)
If I try to add Tap gesture on control, it works perfectly. If I try to addTap gesture on any of the other items, it doesn't work.
isUserInteractionEnabled
is enabled for every element. I also called BringToFront
for each element.
I also tried to set UIGestureRecognizerDelegate
and detect Touch
event, it isn't detecting as well.
Any idea?
Here is the code,
func setGesture() {
// self.isUserInteractionEnabled = true
// containerView.isUserInteractionEnabled = true
label.isUserInteractionEnabled = true
// exclamationMark.isUserInteractionEnabled = true
self.bringSubview(toFront: containerView)
containerView.bringSubview(toFront: exclamationMark)
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapSavingLabel)))
//exclamationMark.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapExclamationMarkButton)))
//self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selfTapped)))
}
@objc func didTapExclamationMarkButton() {
delegate?.didTapExclamationMarkButton()
}
@objc func didTapSavingLabel() {
delegate?.didTapSavingLabel()
}
@objc func selfTapped() {
print("Self Tapped")
}
If i uncomment the Tap gesture on Self, it works well.
ios swift xcode
add a comment |
up vote
1
down vote
favorite
View hierarchy is like this,
- control (UIView)
- container (UIView)
- icon (UILabel)
- label(UILabel)
If I try to add Tap gesture on control, it works perfectly. If I try to addTap gesture on any of the other items, it doesn't work.
isUserInteractionEnabled
is enabled for every element. I also called BringToFront
for each element.
I also tried to set UIGestureRecognizerDelegate
and detect Touch
event, it isn't detecting as well.
Any idea?
Here is the code,
func setGesture() {
// self.isUserInteractionEnabled = true
// containerView.isUserInteractionEnabled = true
label.isUserInteractionEnabled = true
// exclamationMark.isUserInteractionEnabled = true
self.bringSubview(toFront: containerView)
containerView.bringSubview(toFront: exclamationMark)
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapSavingLabel)))
//exclamationMark.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapExclamationMarkButton)))
//self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selfTapped)))
}
@objc func didTapExclamationMarkButton() {
delegate?.didTapExclamationMarkButton()
}
@objc func didTapSavingLabel() {
delegate?.didTapSavingLabel()
}
@objc func selfTapped() {
print("Self Tapped")
}
If i uncomment the Tap gesture on Self, it works well.
ios swift xcode
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
@SamuelLiew - I realize that, and I had created a chat room, however... when I went to invite the OP, I see he has a rep of only 6, which is not high enough to talk in chat.
– DonMag
Nov 9 at 13:48
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
View hierarchy is like this,
- control (UIView)
- container (UIView)
- icon (UILabel)
- label(UILabel)
If I try to add Tap gesture on control, it works perfectly. If I try to addTap gesture on any of the other items, it doesn't work.
isUserInteractionEnabled
is enabled for every element. I also called BringToFront
for each element.
I also tried to set UIGestureRecognizerDelegate
and detect Touch
event, it isn't detecting as well.
Any idea?
Here is the code,
func setGesture() {
// self.isUserInteractionEnabled = true
// containerView.isUserInteractionEnabled = true
label.isUserInteractionEnabled = true
// exclamationMark.isUserInteractionEnabled = true
self.bringSubview(toFront: containerView)
containerView.bringSubview(toFront: exclamationMark)
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapSavingLabel)))
//exclamationMark.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapExclamationMarkButton)))
//self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selfTapped)))
}
@objc func didTapExclamationMarkButton() {
delegate?.didTapExclamationMarkButton()
}
@objc func didTapSavingLabel() {
delegate?.didTapSavingLabel()
}
@objc func selfTapped() {
print("Self Tapped")
}
If i uncomment the Tap gesture on Self, it works well.
ios swift xcode
View hierarchy is like this,
- control (UIView)
- container (UIView)
- icon (UILabel)
- label(UILabel)
If I try to add Tap gesture on control, it works perfectly. If I try to addTap gesture on any of the other items, it doesn't work.
isUserInteractionEnabled
is enabled for every element. I also called BringToFront
for each element.
I also tried to set UIGestureRecognizerDelegate
and detect Touch
event, it isn't detecting as well.
Any idea?
Here is the code,
func setGesture() {
// self.isUserInteractionEnabled = true
// containerView.isUserInteractionEnabled = true
label.isUserInteractionEnabled = true
// exclamationMark.isUserInteractionEnabled = true
self.bringSubview(toFront: containerView)
containerView.bringSubview(toFront: exclamationMark)
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapSavingLabel)))
//exclamationMark.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapExclamationMarkButton)))
//self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selfTapped)))
}
@objc func didTapExclamationMarkButton() {
delegate?.didTapExclamationMarkButton()
}
@objc func didTapSavingLabel() {
delegate?.didTapSavingLabel()
}
@objc func selfTapped() {
print("Self Tapped")
}
If i uncomment the Tap gesture on Self, it works well.
ios swift xcode
ios swift xcode
edited Nov 10 at 22:16
halfer
14.2k757106
14.2k757106
asked Nov 7 at 13:51
Haseeb Iqbal
66
66
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
@SamuelLiew - I realize that, and I had created a chat room, however... when I went to invite the OP, I see he has a rep of only 6, which is not high enough to talk in chat.
– DonMag
Nov 9 at 13:48
add a comment |
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
@SamuelLiew - I realize that, and I had created a chat room, however... when I went to invite the OP, I see he has a rep of only 6, which is not high enough to talk in chat.
– DonMag
Nov 9 at 13:48
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
@SamuelLiew - I realize that, and I had created a chat room, however... when I went to invite the OP, I see he has a rep of only 6, which is not high enough to talk in chat.
– DonMag
Nov 9 at 13:48
@SamuelLiew - I realize that, and I had created a chat room, however... when I went to invite the OP, I see he has a rep of only 6, which is not high enough to talk in chat.
– DonMag
Nov 9 at 13:48
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I created the outlet in Interface Builder and connect to label
var.
Updated to new answer.
I think you have "exclamation" view over the label.
The rest is the next code.
- controller
-- container
--- label
class ViewController: UIViewController {
@IBOutlet weak var container: UIView!
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.label.isUserInteractionEnabled = true
self.view.bringSubviewToFront(self.container)
let tap = UITapGestureRecognizer(target: self, action: #selector(tapPerformed(_:)))
self.label.addGestureRecognizer(tap)
}
@objc func tapPerformed(_ tap: UITapGestureRecognizer) {
debugPrint(#function)
}
}
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
add a comment |
up vote
0
down vote
The problem is that one or more of the label's superview has a frame size of 0,0
. When that view's .clipsToBounds
property is false
, it allows its subviews (the label, in this case) to be seen on-screen, but it extends outside the bounds of its superview.
Any view in that condition will not respond to touches / gestures.
Once you solve your layout issues and have the frames properly set up, the Tap Gesture added to the label will work as intended.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I created the outlet in Interface Builder and connect to label
var.
Updated to new answer.
I think you have "exclamation" view over the label.
The rest is the next code.
- controller
-- container
--- label
class ViewController: UIViewController {
@IBOutlet weak var container: UIView!
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.label.isUserInteractionEnabled = true
self.view.bringSubviewToFront(self.container)
let tap = UITapGestureRecognizer(target: self, action: #selector(tapPerformed(_:)))
self.label.addGestureRecognizer(tap)
}
@objc func tapPerformed(_ tap: UITapGestureRecognizer) {
debugPrint(#function)
}
}
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
add a comment |
up vote
0
down vote
I created the outlet in Interface Builder and connect to label
var.
Updated to new answer.
I think you have "exclamation" view over the label.
The rest is the next code.
- controller
-- container
--- label
class ViewController: UIViewController {
@IBOutlet weak var container: UIView!
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.label.isUserInteractionEnabled = true
self.view.bringSubviewToFront(self.container)
let tap = UITapGestureRecognizer(target: self, action: #selector(tapPerformed(_:)))
self.label.addGestureRecognizer(tap)
}
@objc func tapPerformed(_ tap: UITapGestureRecognizer) {
debugPrint(#function)
}
}
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
add a comment |
up vote
0
down vote
up vote
0
down vote
I created the outlet in Interface Builder and connect to label
var.
Updated to new answer.
I think you have "exclamation" view over the label.
The rest is the next code.
- controller
-- container
--- label
class ViewController: UIViewController {
@IBOutlet weak var container: UIView!
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.label.isUserInteractionEnabled = true
self.view.bringSubviewToFront(self.container)
let tap = UITapGestureRecognizer(target: self, action: #selector(tapPerformed(_:)))
self.label.addGestureRecognizer(tap)
}
@objc func tapPerformed(_ tap: UITapGestureRecognizer) {
debugPrint(#function)
}
}
I created the outlet in Interface Builder and connect to label
var.
Updated to new answer.
I think you have "exclamation" view over the label.
The rest is the next code.
- controller
-- container
--- label
class ViewController: UIViewController {
@IBOutlet weak var container: UIView!
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.label.isUserInteractionEnabled = true
self.view.bringSubviewToFront(self.container)
let tap = UITapGestureRecognizer(target: self, action: #selector(tapPerformed(_:)))
self.label.addGestureRecognizer(tap)
}
@objc func tapPerformed(_ tap: UITapGestureRecognizer) {
debugPrint(#function)
}
}
edited Nov 7 at 15:49
answered Nov 7 at 14:41
sergiog90
9415
9415
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
add a comment |
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
Please check the code in Edited question.
– Haseeb Iqbal
Nov 7 at 14:48
add a comment |
up vote
0
down vote
The problem is that one or more of the label's superview has a frame size of 0,0
. When that view's .clipsToBounds
property is false
, it allows its subviews (the label, in this case) to be seen on-screen, but it extends outside the bounds of its superview.
Any view in that condition will not respond to touches / gestures.
Once you solve your layout issues and have the frames properly set up, the Tap Gesture added to the label will work as intended.
add a comment |
up vote
0
down vote
The problem is that one or more of the label's superview has a frame size of 0,0
. When that view's .clipsToBounds
property is false
, it allows its subviews (the label, in this case) to be seen on-screen, but it extends outside the bounds of its superview.
Any view in that condition will not respond to touches / gestures.
Once you solve your layout issues and have the frames properly set up, the Tap Gesture added to the label will work as intended.
add a comment |
up vote
0
down vote
up vote
0
down vote
The problem is that one or more of the label's superview has a frame size of 0,0
. When that view's .clipsToBounds
property is false
, it allows its subviews (the label, in this case) to be seen on-screen, but it extends outside the bounds of its superview.
Any view in that condition will not respond to touches / gestures.
Once you solve your layout issues and have the frames properly set up, the Tap Gesture added to the label will work as intended.
The problem is that one or more of the label's superview has a frame size of 0,0
. When that view's .clipsToBounds
property is false
, it allows its subviews (the label, in this case) to be seen on-screen, but it extends outside the bounds of its superview.
Any view in that condition will not respond to touches / gestures.
Once you solve your layout issues and have the frames properly set up, the Tap Gesture added to the label will work as intended.
answered Nov 8 at 16:00
DonMag
15.2k2825
15.2k2825
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190817%2fuitapgesturerecognizer-not-working-on-uilabel-but-working-on-parent-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew♦
Nov 9 at 8:30
@SamuelLiew - I realize that, and I had created a chat room, however... when I went to invite the OP, I see he has a rep of only 6, which is not high enough to talk in chat.
– DonMag
Nov 9 at 13:48