iOS - Double Tap Gesture does not work on top of a UIWebView - objective-c

I have a viewController that has several items added programatically. A UILabel and a UIWebView including a scroll view.
Now I have added a swipe gesture onto the viewController using storyboard and when run all seems ok.
The issue comes when I try to swipe over the the UIWebview, it does not trigger the the Swipe gesture and looks as if its cancelling it out.
How can i enable it so the gesture works over the whole view but yet keeping the UIWebview functionality?

You can set
[UIWebView.scrollView setDelegate:myViewController]
and implement in your view controller
-(void)scrollViewDidScroll:(UIScrollView *)sender
But to really pass events, you will need more:
http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/

Related

Is there a way to make some parts of UITableView not scrollable?

I'm using a paper fold animation To show some content from the top of the screen, over the tableView.
Right now i have a button that triggers this folding action.
I would like instead to trigger this action by swiping from top to bottom. but my TableView is full screen, so i figured if there is a way to make on UITableViewCell, or a part of the table, not scrollable, for it to trigger the Fold swipe instead.
I tried using the UISwipeGestureRecognizer But it doesn't work so well...
There are several ways to stop UITableView from scrolling. UITableView is a subclass of UIScroll view so you can use the UIScroll view methods to stop the table view being scrollable. So in your tableViewController you can call [[self tableView] setScrollEnabled:NO]. You should also be able to stop any user interaction on the table view by calling [[self tableView] setUserInteractionEnabled:NO] (a method on UIView).
You could subclass the UITableView and override the setContentOffset: method (another scrollView method), and only call [super setContentOffset:] when you actually want the table view to scroll (it's possible that you may need to override other methods as well.
You can also get hold of the pan gesture recogniser that the scrollView is using, this allows you to see exactly what messages the scrollView is getting for scrolling and you may be able to adjust the scroll offset accordingly [[self tableView] panGestureRecognizer]. Once you have the panGestureRecognizer you should be able to set it to wait for your swipeGestureRecognizer to fail using [UIPanGestureRecognizer requireGestureRecognizerToFail:. Which will mean that the pan gesture recogniser the scroll view uses will only start working if the swipe fails, you may need to make it so the swipeGestureRecognizer fails if it doesn't start near the edge of the screen.

Custom UIScrollView Gesture

I have a collection view cell which contains an UIScrollview in which all of the content sits. I want to have a gesture that allows users to swipe down when the cell is at 0,0 and then that fades away into the list view of the collection view.
However, I still want the users to be able to scroll down into the rest of the cell content.
Should this be contained in the same gesture? If so, how do I override a scrollview's gesture?
Thanks.
Yea just try implement this method from UIScrollViewDelegate:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
Get scrollView and calculate gestures and make behaviour. And look other methods for make best visual effect :)

iOS perform action before handling touch events

I'm trying to recreate the Facebook slideout menu trick (yes I know there's lots of libraries already).
When a user touches a button on the screen, a new view controller is switched in and a rendered bitmap of the previous screen is shown in the foreground of this new view. The uiimageview has a pan gesture recogniser attached to it to allow it to be moved around on the screen.
Currently it's requiring two touches to activate the gesture recogniser, once to bring in the new view controller, and once for the pan gesture to move the uiimageview.
My question is, on touch down can I bring in the new view controller and then pass the touch events to the uiimageview? Or is there any other trick that will help?
I haven't managed to achieve this exactly, but instead I've subclassed UIViewController so the root view controller never changes, just the content that's being displayed.

Subview of Scrollview doesn't register touch events

I'm struggling with this problem, and although there are quite some threads on this issue I've not figured it out yet.
I want to load a button into a subview of a scrollview. If I test this subview alone, the button works fine. Also, when I add the button to the scrollview directly, it works fine. But the two combined I don't get any touch event on the button.
My view hierarchy:
UIScrollView
UIView
UIButton (A)
UIButton (B)
So button B works fine, A doesn't.
I've tried messing around with the attributes like Cancellable Content Touches, but so far no luck. I'm loading the subview from the storyboard with:
ViewVC *viewVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewVC"];
From the posts I've read, this should just work, so either I'm missing something vital, or I've messed up some attributes along the way. Should I use a delegate to pass the events, or should this be done automatically?
Give your views some colours, and check if one of them is obscuring the other preventing it from being touched. Maybe you UIView is overlapping your UIButton(B), preventing it from being touched.
How are you sure you're adding it?
Make sure you're calling addSubview: on your UIScrollView with your subview as the parameter?

UIScrollView on UIWebView and UITapGestureRecognizer conflicts

I have a UITapGestureRecognizer on a UIViewController, which has a UIScrollView and UIWebView inside. It recognizes the tap gesture only after I scroll the UIWebView. How could I prevent this ?. Basically I want the tap gesture to be detected, when I am not scrolling the web view. I looked around and the closest I found is this:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
return YES;
}
but not sure how can I use this to disable the tap while scrolling. Any idea?
Another thing I want to do is to disable the UITapGestureRecognizer, when a link on the UIWebView is clicked (shouldStartLoadWebRequest is called). I checked that the tap gesture recognizer is called, before the shouldStartLoadWebRequest is called. Basically when clicking on a link on a UIWebView, it shouldn't trigger the action invoked by the UITapGestureRecongnizer. Any idea on how to do this?
So Apple's documentation strongly recommends you don't nest a UIWebView inside a scroll view:
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
It is possible on iOS 5 and above to get direct access to the underlying scroll view on a UIWebView (using the scrollView) property - playing around with this might help you.