Making Multiview Button Tappable - ios

This is currently a UIStackView with a UIImageView and a UILabel.
I want the entire thing to be tappable.
My poor man's solution at the moment is to overlay a UIView on top of the UIStackView and add a UITapGestureRecognizer into the mix. But it sucks imo.
If I add UITapGestureRecognizer to UIStackView, nothing happens because subviews fill up the UIStackView.
What is best practice to turn this into a button?

nothing happens because subviews fill up the UIStackView.
Right, but if you turn off the userInteractionEnabled of those subviews, the touch falls through to the UIStackView and the gesture recognizer attached to the UIStackView will work.

Related

How to handle an UIScrollView in an UIScrollView

I want to use an UIScrollView in an UIScrollView. I think it would be clearer with a
picture
The black border is the border of the screen, the purple is the first UIScrollView and the blue is the second UIScrollView. The arrows show the direction of the scroll.
When I try to put the second UIScrollView in the first with a different scrolling direction, the second show the content twice... I made a video
I have created design for you to explain how to add scroll view inside scroll view.
Here see the following image with constraints.
Note: This is static view not dynamic, This is create to clear concept of ScrollView inside ScrollView. If you are planning to make ScrollView with design then you need to do some more study on AutoLayout with ScrollView.

UIButton inside of a scrollview isn't clickable

I have an app where I have a couple buttons inside of a UIScrollview. My view hierarchy is like this:
-- UIScrollview
-- UIView (content view)
-- UIView
-- UIButton
-- UIView
-- UIButton
-- UIView
-- UIButton
But the UIButton isn't clickable. Is it possible that the scrollview is blocking clicks? I checked for:
covering subviews;
user interaction enabled = true (on all views);
Scrollview Delay touch down = false;
Scrollview can cancel on scroll = false
The content view clips to bounds. Cutting off anything outside of the view.
but I couldn't find anything.Is there an issue with buttons and scrollviews?
Thanks :)
Is it possible that the scrollview is blocking clicks?
Not inherently, no.
Is there an issue with buttons and scrollviews?
In a word: no. Obviously buttons inside scroll views work just fine all the time. You probably use them every day in many apps that you use.
If your buttons are not tappable in a scroll view, that's because of something you are doing wrong. It is not because of anything in the nature of buttons and scroll views.
Can you check if you have overlapped a UIView with the UIButton.
And enableUserInteraction is not required for UIViews, try disabling it.
Also check if you have linked the right UIButton event with the action method.

Drag Drop UIImageView into subView - Swift 3

I'm newbie to Swift and trying to drag a UIImageView into UiView, I have three UIViews i have to drag the UIImageView into any three UIViews , not anywhere.
I have tried touchesBegan, touchesEnded method, but drag drop is not on inside this any of 3 UIViews.
Please anyone give me skeleton to drop the UIImageView to anyone of three UIViews,
UIImageView and all UIViews probably share the same superView, if you want to put UIImageView inside of UIView you need to move it. I mean you need to remove it from superView and add it to the view beneath it (if they intersect)
Here's what you're gonna do:
When User touches (pans) the UIImageView, move it to superView (If It's already there, it's ok, if It's in one of UIViews, you need to remove it from them, and add it to superView)
When user touch has ended, UIGestureRecognizer will also inform you about it, at that moment check if there's any UIViews beneath your UIImageView or not, if not do nothing else remove it from superView and add the view beneath it.
There's also a WWDC video which covers advanced touch handling techniques.

UISwipeGestureRecognizer over UIButtons

I want swipes to be detected on the lower half of the screen. That part of the screen can have UIButtons as well. I want the swipes to take priority over the buttons (that is, if you swipe over the buttons, the buttons are ignored). But I want the buttons to work if you just tap on them.
I tried placing a transparent view over the buttons with the UISwipeGestureRecognizer attached, but obviously that makes the the buttons not to work as it swallows all touches including taps.
I also tried placing the transparent view behind the buttons, but then the UIButton event handling interferes with the swipe when you swipe over the button.
What's the best way to get this working?
I can think of a solution where the buttons would just be UIImageViews with attached UITapGestureRecognizers so you can then prioritize between the tap recognizers and the swipe recognizers.
But I'd like to keep the buttons as UIButtons to take advantage of the highlighted stuff.
You may try adding the UISwipeGestureRecognizer to the superview of the UIButton.
i resolve same issue.
you just subclass UIButton and override 'touches~' method.
and then connect your customButton to it's parentView via some delegate.

Scroll View doesn't scroll when touching and holding then swiping

I have UIScrollView with other UIView elements inside. My other UIView elements are mostly segmented controls. If I click on a UISegmentedControl and hold for a second and then try to scroll, then no scrolling happens. I can only scroll when my finger touches and swipes immediately. I checked other iOS applications such as mail. The behavior was that you touch and hold on a mail, then it's highlighted, but as soon as finger moves away, the scrolling happens and highlighting is undone. How can I implement this behavior?
The issue was the property of UIScrollView. The property canCancelContentTouches was set to NO. Because of that, touch events were handled by subviews of scroll view and swiping didn't cause scrolling.
You can follow one of these steps:
If you are using UISegmentedControl over you UIScrollView, instead of that, add the UISegmentedControl over your controller's view.
If you want to use UISegmentedControl over your scrollView, then you have to create a custom scrollView by creating a subclass of UIScrollView and use an image view instead of UISegmentedControl adding the labels which can act as the segments. This is because your UISegmentControl itself is a touch handler and it breaks the UIResponder chain. So, the scrolling might face issues during the touch events.
Please let me know if any of these works. Thanks :)

Resources