UIMenuController not showing when UICollectionViewCell's subView has userInteraction Enabled - ios

Basically I have an imageView inside cell whose isUserInteractionEnabled is set to true as it has a UITapGestureRecognizer. Now the problem is when I long press the cell outside the imageView area it shows the menu but when I long the imageView itself the menu isn't shown. I didn't understand the behaviour.
I also noticed that even if I remove UITapGestureRecognizer, it still doesn't work. So it has something to do with isUserInteractionEnabled property.

Just disable the user interaction on the image view, because it blocks the interaction on the cell.
imageView.isUserInteractionEnabled = false

Related

Disable touch on scroll, enable gestures on its subviews?

I have to disable scrolling on scrollview, so it can be scrolled only by software and not by the user.
scrollView.isUserInteractionEnabled = false
This scrollview has some views, and they have TapGesture on them, I enabled their interaction :
view.isUserInteractionEnabled=true
But it will not work unless I enable the interaction on the scroller.
Is there any other way to achieve my goal ?
Don't use isUserInteractionEnabled to disable scroll on your tableView. Use isScrollEnabled instead of isUserInteractionEnabled and you don't need to change anything of your view
scrollView?.isScrollEnabled = false;
If you set isUserInteractionEnabled to false, it will ignore touchs on subviews of tableView, doesn't matter isUserInteractionEnabled of the subview is true or false.
Set isScrollEnabled to false instead of userInteractionEnabled.
scrollView.isScrollEnabled = false
isScrollEnabled
If the value of this property is true , scrolling is enabled, and if
it is false , scrolling is disabled. The default is true. When
scrolling is disabled, the scroll view does not accept touch events;
it forwards them up the responder chain.

UITableView cancels UITapGesture

uitableviewdidselect cancel outs tap gesture action
there is an UIImageView in cell.contentView and there is a tap gesture to enlarge the image the control is not going to the Tap Gesture action its passing to the tableview didselect delegate ? I am using UITableView class for my table already did userInteractionEnabled=YES & cancelsTouchesInView = NO
Make sure you set
tapGestureRecognizer.cancelsTouchesInView = NO;
It won't work because table view can't take two user interactions at a time. First it will give priority to didSelectRowAtIndexPath. You need to disable user interaction on cells. So that tap gesture will be called. Make sure that user interaction enabled for imageView.

How to prevent a UILabel from blocking a touch to a parent UIButton in Swift?

I have a UIButton that has four child UILabels that contain information about the button's functionality. When I click the center of the button the action does not fire because it is being blocked by the UILabels but when I click the outside of the button the action does fire. Is there a way to prevent the UILabels from blocking the action firing?
You'll need to set isUserInteractionEnabled = false on any view that is above the button, or a subview of it.
By default UILabel have it set to false, but as you mentioned in the comments, UIStackView does not. So calling isUserInteractionEnabled = false on it will do the trick ┌( ಠ‿ಠ)┘

UIGestureRecognizer on UILabel inside UIView inside UIScrollview

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...
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.
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...

User Interaction enabled No Only to the parent

I have one scroll view (UserInteractionEnabled = No) with one image view as its subview.
I am assigning tap gesture to imageview but it is not working even if imageview is UserInteractionEnabled because Its parent (ScrollView) is not.
How can I resolve this conflict.
There is no reason to disable user interaction on a scroll view. If you want to block the scrolling, disable it using the scrollEnabled property.
Don't set scroll view (UserInteractionEnabled = No) because it will set to all its subViews.
hope it will work.

Resources