Changing the zoom out action for a UIWebView - cocoa-touch

I'm trying to change the way a UIWebView reacts when the user do a pinch out gesture (when he's doing that, I zoom out and show multiple webView).
I see 2 solutions but I can't make them work :
Setting scalesPageToFit to YES, and
then getting events that are sent by
the API to change the behavior.
Problem: I don't find how to catch those events
Setting
scalesPageToFit to NO, and adding a
PinchGestureRecognizer on the parent
of the UIWebView. Problem:
The gesture is not well recognize
since there are conflicts with the
scrolling. If the user starts moving
the first finger before putting down
the second finger, the scroll begin
and the pinchGesture is not
recognize.
Do you have an idea ?

Ok, the anwser is just to set the delegate of my UIPinchGestureRecognizer to self and to override
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*) otherRecognizer
{
return YES;
}
Now the pinch is recognized even if the scroll began in the UIWebView

Related

Handle tap event by subview of UIScrollView while scrolling

I have custom UIScrollView subclass with some content views inside. In some of them I have UITapGestureRecogniser. All works fine when scroll view is not scrolling. But when it scrolling content views does not receive tap action. What is the simplest solution to handle tap action by subview while scroll view is scrolling?
Details:
MyScrollView scrolls horizontally. It contains a lot of content views (e.g. MyContentView). Each MyContentView has width about one third of MyScrollView width. So there are about 3-4 visible MyContentView elements at a moment. The main behavior of MyScrollView is to 1)make sure that after scrolling one of MyContentView elements will be at center of screen and 2)to scroll to center of MyContentView if user taps on it. So the main answer I hope to get is how to "properly" implement handling of tap action in MyContentView while MyScrollView is decelerating.
I found some same questions and answers but none of them satisfied me. The best was to implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: of UITapGestureRecogniser delegate. But in this case I sometimes (when I tap, make smaaaal drag and release finger so tap is steel recognizable(lets called it quasi tap)) have both tap and scroll events and it leads to bugs for me even if scroll view is not scrolling when I begin tap. When user make quasi tap my application tries to scroll to tapped MyContentView element and than immediately handle normal scrolling. It seems even more terrible, due to some other functionality start to perform after handling tap (it must not perform when normal scrolling).
I need solution where scroll view wait enough to decide it is not tap event and only then make scroll. Otherwise if tap event had recognized scroll must not happen.
You can go with the custom delegates methods as well, using #protocol. Implement those delegate methods in view controller where your UIScrollView has been added.
like in MyContentView:
In touchesBegan method,
[self.delegate contentViewTapped:self];
Now in ContainerView class where scroll view is added, implement that method:
- (void)contentViewTapped:(MyContentView *)myContentView {
NSLog (#"ContentView no: %d", myContentView.tag); // if tag has been set while adding this view to scrollview.
}
Go through the examples for #protocol.
Hope this is what you required.
Enjoy Coding :)
This is built into UIScrollView - take a look at the delaysContentTouches and canCancelContentTouches properties. This should alleviate the problem when dragging a small bit after a tap.
This is all system built-in behaviour. I would suggest sticking with what Apple has provided for the feel of your interface (how it reacts to small drags, for instance) so that your app doesn't feel out of place on a user's phone.
EDIT:
Alternatively, you could disable scrolling of your scroll view in you gesture recognizer and re-enable it once it's ended/cancelled.
Further Edit:
I don't understand - I've created a sample project that illustrates how to intercept touches in a subview of a scroll view using gesture recognizer delegate methods. Play close attention to the "Cancellable Content Touches" and "Delays Content Touches" properties of the scroll view. They're both YES for very important reasons.
You scroll view should be delaying content touches until it has determined if the user is attempting a tap, pseudo-tap (as you put it), or a pan for the scroll view. Apple has already written the functionality you're trying to build; UIScrollView will already do what you want.
The problem is that the system doesn't want a scroll view's subviews intercepting tap events while the scroll view is scrolling. To this end, it cancels touch events if it determines that the user is actually trying to pan. Setting "Delays Content Touches" enables this behaviour. Ensure it's turned on and you should be fine.

TTPhotoViewController - disable dragging

I'm trying to customize the three20 TTPhotoViewController so that the first & last images cannot be dragged.
Example of what I am trying to prevent.
https://plus.google.com/photos/109413514618904450093/albums/5730490807945885537?authkey=CMTi6OfqhLS2NQ
The image shows the currently selected image has been dragged upwards. This behaviour does not occur on the central images only the first & last.
The code responsible for this behaviour is in the TTScrollView. If it was a uiscrollview I would just set bounces to NO.
Can anyone tell me how I can achieve this result?
I think the issue is in TTScrollView:resistPageEdges but my hacking has left me nowhere
TTPhotoViewController delegates TTScrollViewDelegate.
TTScrollViewDelegate has -(void)scrollViewWillBeginDragging:(TTScrollView *).
TTScrollView has (void)cancelTouches.
Therefore, you can write this in your own subclass of TTPhotoViewController.
- (void)scrollViewWillBeginDragging:(TTScrollView *)scrollView {
[scrollView cancelTouches];
}
Every time a user try to drag, it will cancel any active touches and resets everything to an untouched state.

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.

NSTextField is not working over Full Screen

NSTextfield is not working when I make a full screen app.
I have also made first responder of textfield. How can I make it enable and working?
Full Screen window won't get any keyboard events the way it is, due to the fact that it was created with with the NSBorderlessWindowMask style mask. Apparently windows of this type can't become "key windows". However, you can fix this problem by subclassing NSWindow and overriding the canBecomeKeyWindow method.
- (BOOL)canBecomeKeyWindow
{
return YES;
}

touchesShouldBegin Returns NO in ScrollView: Then What?

I'm getting exactly the behavior I want in a UIScrollView: when I return NO for touchesShouldBegin, the scrolling behavior happens. Otherwise, the content views get the event.
However, I'd like to show something on touch down and touch up when the scrolling behavior is occurring. Unfortunately, returning NO for touchesShouldBegin blocks the touchesBegan and touchesEnded methods.
The delegate method:
-(void) scrollViewWillBeginDragging:(UIScrollView *)scrollView {
doesn't work because sometimes the user touches but doesn't drag. How can I register touchUp and touchDown events yet preserve scrolling behavior?
You cannot. While a UIScrollview is scrolling, the subview(s) (and the view itself) are not updated or redrawn. It only scrolls. It is just how the UIResponder chain works in this scenario.