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.
Related
I have created a scrollview, to scroll through an array of images, and I have a button and soon to be 6 more on the screen. Now to make the photo nicer, I would simply like to make the buttons disappear and when tapped on again to appear.
Now I know how to do this with just a regular view with simple isHidden, and how to make it reappear when tapped on, but I am largely confused on how to do it on a scrollview because on a regular view, I just put a button over the whole screen but with the scrollview I can't. Any ideas anyone? Still getting better at this one step at a time, and one question at a time.
Here is a screenshot: http://imgur.com/a/Ll6QO
Use a gesture recognizer on the scrollview.
Add a touch gesture recognizer to toggle the visibility of your buttons. Be sure that the gesture recognizer doesn't cancel touches in view, otherwise you won't be able to scroll.
There's a input toolbar appearing at bottom of screen, a UITextView which be contained becomes firstResponser when user wanna input something, and at this moment the input toolbar animates to the top of UIKeyboard.
What I want to do is to make input toolbar go back to the bottom when the tap event begins, so I implement a custom gesture TouchDownGestureRecognizer adding to a UITableView (list history messages). Then the problem appeared: The UITableView can't scroll when touchDown.
So how to recognize custom touchDown gesture and make scrollView scrollable Simultaneously?
Thanks in advance!
It seems that it is a little difficult to solve the problem by this way, so I do touch down stuff in the - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView method.
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 :)
I have a UIScrollView that contains several UIButtons. Each button is wired up to take an action when the user inputs a touch up event, so they are able to place their finger on the button and it will not be selected until it is raised. Currently, if I made a swipe gesture to scroll the UIScrollView quickly, then the scroll view moves as expected even if the gesture happens directly over a UIButton. HOWEVER, if I hold my finger down too long on a UIButton (about 1 second), the UIScrollView will no longer recognize the gesture and will not be able to scroll until the finger is lifted up.
I am wondering if their is a way to always have the UIScrollView recognize the scroll gesture? Note that this is not an issue if I touch the UiScrollView in a location without a UIButton - it then scrolls as expected.
It may worth a try to let your UIButton respond to UIControlEventTouchDown (maybe with an empty action). I'm not sure if this will work, but conceptually I think it should let the UIButton capture the touch immediately.
(Also make sure you don't enable delaysContentTouches on your scrollview.)
I found the answer to this here: UIScrollview with UIButtons - how to recreate springboard?
Essentially, I had to extend UIScrollView and override touchesShouldCancelInContentView, having it always return YES.
I have a view with three image views hangin' around. These image views respond to certain gestures. I want to allow a certain gesture (such as a swipe across the screen) to do an action to all of the imageviews (such as, say, delete them all).
The only way I can think of having the swipe gesture be recognized everywhere on the screen is by overlaying a clear superview that looks for swipe gestures. My problem; however, is that I don't know how to let the superview ignore all other gestures so I can still interact with the imageviews below. Is there an easier way to handle this problem?
Try adding the gesture to your view's window rather than the view:
[self.view.window addGestureRecognizer:gesture];