Is there any way to find gesture recognizer in UIWebView - iphone

I am trying ebook reading app. In that I want create UIActionSheet by clicking on the index page link..For that how can I identify the touch event in webView as WebView already have the inbuilt longTouch event. Is there any way to identify that longtouch event in webView?

Just overwrite below method to work our gerstures
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer
*)otherGestureRecognizer
{
return YES;
}
For adding longPress add to your view
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longPress:)];
longPress.minimumPressDuration=0.8;
longPress.delegate = self;
[self addGestureRecognizer:longPress];
[longPress release];
- (void)longPress:(UILongPressGestureRecognizer*)gesture
{
}

Related

iphone development : gesture recognition scrolling enabled simultaneously

In my app I need have a swipe gesture recogniser on my background scroller for the up direction. Here is my code below
It is in viewDidLoad
UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeRecognizer:)];
Swipe.direction = UISwipeGestureRecognizerDirectionUp;
[backgroundScroller addGestureRecognizer:Swipe];
and it is the SwipeRecognizer:
- (void) SwipeRecognizer:(UISwipeGestureRecognizer *)sender {
if (sender.direction | UISwipeGestureRecognizerDirectionUp){
NSLog(#" *** SWIPE UP ***");
}
}
The problem is I cant enable scrolling and capture the gesture simultaneously. when I said scrolling is not enabled, I can recognise the gesture. But I need to to scrolling and gesture recognition simultaneously. isn't it possible?
Override the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method to don't block the UIScrollViews Pan recognizer
And it will work…
Dont forget to add delegate to self for gesture recogniser. As mentioned in #death7eater's comment.
I solved my problem like that:
This is for the viewDidLoad:
UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeRecognizer:)];
Swipe.direction = UISwipeGestureRecognizerDirectionUp;
[backgroundScroller addGestureRecognizer:Swipe];
Swipe.delegate = self;
This is the SwipeRecognizer method:
- (void) SwipeRecognizer:(UISwipeGestureRecognizer *)sender {
if (sender.direction | UISwipeGestureRecognizerDirectionUp){
NSLog(#" *** SWIPE UP ***");
}
}
And thanks to #lukaswelte this allows to perform multiple gestures simultaneously:
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

how to add UISwipeGestureRecognizer to webview

Hi all i have a problem with UISwipeGestureRecognizer to web view i am using below code to add swipe recognizer but its not working .how can solve this problem please help me
UISwipeGestureRecognizer *DownRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(DownSwipeHandle:)];
DownRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
[DownRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:DownRecognizer];//even if i use not working[_webview addGestureRecognizer:DownRecognizer];
DownRecognizer.delegate=self;
[DownRecognizer release];
use this method it will be work.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

I have a UITapGestureRecognizer added to an UIViewController's view that is in a UITableViewCell in a UITableView, why won't it fire?

The title is pretty explanatory, but I have a UITableView that I am populating with custom UITableViewCells.
Inside of these custom UITableViewCells, I am adding custom UIViewControllers that display custom images.
To this UIViewController's UIView, I am adding a UITapGestureRecognizer as follows:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleTap:)];
recognizer.numberOfTapsRequired = 1;
recognizer.delegate = self;
[self.imageView addGestureRecognizer:recognizer];
[recognizer release];
}
-(void)handleTap:(UITapGestureRecognizer *)sender{
NSLog(#"Handling tap on ArticleTileViewController");
}
When I run the app, the cells are populating the images great, but when I tap on the image(or the custom UIViewController), nothing happens! My NSLog won't fire. I have looked over the code for an hour now, and don't see where I am going wrong.
Does anybody see something I'm missing? Or have they run into this before?
UIImageView objects have their userInteractionEnabled set to NO by default. This might be the case here as well. Add
self.imageView.userInteractionEnabled = YES;
to the viewDidLoad method that you've presented in the question.
If you are trying to get a button on each cell, here is a post on how to do it. Take a look.
iPhone SDK: Opening a cell with a dedicated button, not by cell tapping
- (void)viewDidLoad {
UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)] autorelease];
gesture.delegate = self;
[myWebView addGestureRecognizer:gesture];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

Add a UITapGestureRecognizer to a UIWebView

In iOS, is it possible to put a tap recognizer on a UIWebView, so that when someone single-taps the web view, an action gets performed?
Code below doesn't seem fire handleTap when I tap my webView.
Thanks.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleTap)];
tap.numberOfTapsRequired = 1;
[webView addGestureRecognizer:tap];
[tap release];
-(void) handleTap {
NSLog(#"tap");
}
I found that I had to implement this method to get it to work:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
Your UIViewController subclass should implement UIGestureRecognizerDelegate and return YES from gestureRecognizer: shouldReceiveTouch: when appropriate.
Then you can assign it to the delegate property of your UIGestureRecognizer.
tap.delegate = self;
Add UIGestureRecognizerDelegate to view controller
<UIGestureRecognizerDelegate>
Add Tap Gesture to Webview.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(flip)];
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[_webview addGestureRecognizer:tap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

iPhone - How may I catch a tap into a UIWebView or a UIImageView

I have a View generated like this :
oneView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
oneView.tag = i;
UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap2:)];
[recognizer setNumberOfTouchesRequired:1];
[oneView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];
- (void)handleSingleTap2:(UITapGestureRecognizer *)recognizer {
int viewID = recognizer.view.tag;
NSLog(#"id : %d", viewID);
}
This works, but if I replace the UIView alloc with a UIWebView or UIImageView alloc, then touch event is not triggerred anymore.
How may I make it work ?
set userInteractionEnabled=YES and if needed multipleTouchEnabled=YES
Regarding your question about the UIWebView I suggest you have a look at drawnonward's Answer :
Does UIGestureRecognizer work on a UIWebView?
And for the UIImageView Part see this Tutorial:
UIImageView-with-zooming-tapping
I could not paste the code here but i think this will keep this area cleaner and easier to read.
you must override
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
delegate function and return YES;