Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

UIScrollView touch events delivering

splitsplit Posts: 43Registered Users
I have quite complex problem with UIScrollView which is different from all problems resolved here. Anyway I think what can help me if someone explains me this:

I made up a subclass of UIScrollView and overrode all touch based methods (touchesBegan, touchesMoved...) I filled it only with NSLog, with no [super ...] calling. What I don't understand is that this subclass of UIScrollView still works. I mean it still scrolls. How is this possible. Is there any other place or technique how can object recieve touch events? Or is there another view below actual scroll view (which is still part of UIScrollView) which overrides the hitTest?

I need to track all the scroll view touch events and don't interact with normal scrolling behavior of scroll view. Is there a way to do this?

I'm really not in mood of creating my own scroll view from beginning :)
Post edited by split on
MN.png <a href="http://bit.ly/bzLyFI" target="_blank">Midnight HD</a> ec.png <a href="http://bit.ly/zgoquI" target="_blank">Escapology</a> wb.unitedfla

Replies

  • fiftysixtyfiftysixty Posts: 310Registered Users
    edited November 2009
    Since OS 3.0 (I think) touchesBegin, -Moved etc. have been deprecated in UIScrollView. It's a bummer, though it was apparently done to avoid certain problems. Currently, the only way to customize touch handling in a UIScrollView is with touchesShouldBegin:withEvent:inContentView which is not much to be honest.

    After reading through iPhone Dev Center: iPhone Application Programming Guide: Event Handling I don't think there is a good way for you to do what you want, the only real option being subclassing UIWindow and overriding the sendEvent: method, but calling the superclass implementation so that the touches get sent properly.
    <a href="http://www.fiftysixtysoftware.com" target="_blank">Fifty Sixty Software</a><br />
    <a href="http://www.fiftysixtysoftware.com/blog" target="_blank">iPhone development tips and tutorials</a><br />
    <br />
    <b>Apps in store:</b><br />
    <a href="htt
  • splitsplit Posts: 43Registered Users
    edited November 2009
    Thanks for reply.

    Unfortunately I know about everything what you wrote. I read "Event Handling" chapter about 20 times :) I allready did override sendEvent: method (but in UIApplication) and it may help me but this solution is really not very nice. It is also strange that the view of events when touches began is set to my custom scroll view, but after moving finger a little bit it changes to NULL.

    Anyway there is probably something what is not really documented at all. Originally I thought sendEvent looks for first responder and calls touchesBegin, touchesCancelled ... methods. This is probably not the whole truth.

    Solution: I will create my own scroll view :) Thank you apple :)
    MN.png <a href="http://bit.ly/bzLyFI" target="_blank">Midnight HD</a> ec.png <a href="http://bit.ly/zgoquI" target="_blank">Escapology</a> wb.unitedfla
  • fiftysixtyfiftysixty Posts: 310Registered Users
    edited November 2009
    From what I understand, sendEvent: performs hitTest: on the view hierarchy to find the view that should handle the touch, and then the view either handles it or passes it to its nextResponder (usually the view controller) for handling, and this goes on until a view or view controller handles the touches, or until the UIApplication handles or discards them.

    After the changes in 3.0, I had to create my own scroll view too, but it's very basic: no scroll bars, no kinetic scrolling, but still it scrolls and zooms in and out, and that's what matters to me :)
    <a href="http://www.fiftysixtysoftware.com" target="_blank">Fifty Sixty Software</a><br />
    <a href="http://www.fiftysixtysoftware.com/blog" target="_blank">iPhone development tips and tutorials</a><br />
    <br />
    <b>Apps in store:</b><br />
    <a href="htt
  • splitsplit Posts: 43Registered Users
    edited January 2010
    After quite a long period of time I found solution to all my problems with UIScrollView.

    To be able to track position of touches and also don't interact with UIScrollView I ended up with subclassing application key window (UIWindow) and overriding sendEvent method.

    Here is a code:
    - (void)sendEvent:(UIEvent *)event {
    	[super sendEvent:event];
    	
    	// only if it is a touch event type and we have observer
    	if ((touchesObserver) && (event.type == UIEventTypeTouches)) {
    	
    		// empty sets
    		[beganTouches removeAllObjects];
    		[cancelTouches removeAllObjects];
    		[endTouches removeAllObjects];
    		[moveTouches removeAllObjects];
    		
    		// fill in sets
    		for (UITouch * touch in [event allTouches]) {
    			if (touch.phase == UITouchPhaseBegan) [beganTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseCancelled) [cancelTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseMoved) [moveTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseEnded) [endTouches addObject:touch];
    		}
    		
    		// call methods
    		if ([beganTouches count] > 0) [touchesObserver touchesBegan:beganTouches withEvent:event];
    		if ([cancelTouches count] > 0) [touchesObserver touchesCancelled:cancelTouches withEvent:event];
    		if ([moveTouches count] > 0) [touchesObserver touchesMoved:moveTouches withEvent:event];
    		if ([endTouches count] > 0) [touchesObserver touchesEnded:endTouches withEvent:event];		
    	}
    }
    

    - touchesBegan, touchesCancelled ... are NSMutableSet objects
    - touchesObserver is any UIResponder object and it recieves all touches which occure in application.

    This is much more powerfull than I needed, but it helps me do what I need. Hopefully it will help someone else too :)
    MN.png <a href="http://bit.ly/bzLyFI" target="_blank">Midnight HD</a> ec.png <a href="http://bit.ly/zgoquI" target="_blank">Escapology</a> wb.unitedfla
  • LaMarmotteLaMarmotte Posts: 6New Users
    edited April 2010
    split wrote: »
    After quite a long period of time I found solution to all my problems with UIScrollView.

    To be able to track position of touches and also don't interact with UIScrollView I ended up with subclassing application key window (UIWindow) and overriding sendEvent method.

    Here is a code:
    - (void)sendEvent:(UIEvent *)event {
    	[super sendEvent:event];
    	
    	// only if it is a touch event type and we have observer
    	if ((touchesObserver) && (event.type == UIEventTypeTouches)) {
    	
    		// empty sets
    		[beganTouches removeAllObjects];
    		[cancelTouches removeAllObjects];
    		[endTouches removeAllObjects];
    		[moveTouches removeAllObjects];
    		
    		// fill in sets
    		for (UITouch * touch in [event allTouches]) {
    			if (touch.phase == UITouchPhaseBegan) [beganTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseCancelled) [cancelTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseMoved) [moveTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseEnded) [endTouches addObject:touch];
    		}
    		
    		// call methods
    		if ([beganTouches count] > 0) [touchesObserver touchesBegan:beganTouches withEvent:event];
    		if ([cancelTouches count] > 0) [touchesObserver touchesCancelled:cancelTouches withEvent:event];
    		if ([moveTouches count] > 0) [touchesObserver touchesMoved:moveTouches withEvent:event];
    		if ([endTouches count] > 0) [touchesObserver touchesEnded:endTouches withEvent:event];		
    	}
    }
    

    - touchesBegan, touchesCancelled ... are NSMutableSet objects
    - touchesObserver is any UIResponder object and it recieves all touches which occure in application.

    This is much more powerfull than I needed, but it helps me do what I need. Hopefully it will help someone else too :)


    Hello, could you give us more information about this? I tried to do teh same but without success.

    Thanks
  • splitsplit Posts: 43Registered Users
    edited April 2010
    What's the problem you have? Did you subclass main application window? There is no more information about this. I think I've described it completly.
    MN.png <a href="http://bit.ly/bzLyFI" target="_blank">Midnight HD</a> ec.png <a href="http://bit.ly/zgoquI" target="_blank">Escapology</a> wb.unitedfla
  • rocotilosrocotilos Posts: 3,266iPhone Dev SDK Supporter, Registered Users @ @ @ @ @
    edited April 2010
    What I did is different. Just sharing.

    I have a UIImageView in UIScrollView. So users be able to pan/zoom in as normal. Then when I want to do something on the UIImageView, i just remove the UIImageView from the UIScrollview and then the touches will be effective.
  • MCGMCG Posts: 1New Users
    edited October 2010
    split wrote: »
    After quite a long period of time I found solution to all my problems with UIScrollView.

    To be able to track position of touches and also don't interact with UIScrollView I ended up with subclassing application key window (UIWindow) and overriding sendEvent method.

    Here is a code:
    - (void)sendEvent:(UIEvent *)event {
    	[super sendEvent:event];
    	
    	// only if it is a touch event type and we have observer
    	if ((touchesObserver) && (event.type == UIEventTypeTouches)) {
    	
    		// empty sets
    		[beganTouches removeAllObjects];
    		[cancelTouches removeAllObjects];
    		[endTouches removeAllObjects];
    		[moveTouches removeAllObjects];
    		
    		// fill in sets
    		for (UITouch * touch in [event allTouches]) {
    			if (touch.phase == UITouchPhaseBegan) [beganTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseCancelled) [cancelTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseMoved) [moveTouches addObject:touch];
    			else if (touch.phase == UITouchPhaseEnded) [endTouches addObject:touch];
    		}
    		
    		// call methods
    		if ([beganTouches count] > 0) [touchesObserver touchesBegan:beganTouches withEvent:event];
    		if ([cancelTouches count] > 0) [touchesObserver touchesCancelled:cancelTouches withEvent:event];
    		if ([moveTouches count] > 0) [touchesObserver touchesMoved:moveTouches withEvent:event];
    		if ([endTouches count] > 0) [touchesObserver touchesEnded:endTouches withEvent:event];		
    	}
    }
    

    - touchesBegan, touchesCancelled ... are NSMutableSet objects
    - touchesObserver is any UIResponder object and it recieves all touches which occure in application.

    This is much more powerfull than I needed, but it helps me do what I need. Hopefully it will help someone else too :)

    Thanks,it helps me a lot.:p
  • mejim707mejim707 Posts: 6New Users
    edited May 2012
    I'm looking to track touches in a scroll view as well. In my case I want to be able to have a UIView move with the scroll view as you scroll it. I want the UIView from outside the UIScrollView to move tracking the position of a button within the UIScrollView. So, if you tap the button in the scroll view the outside UIView appears. Then it you scroll the scrollview the UIView moved with the button you just tapped. I can't seem to track touches within the Scroll view even though I've subclassed it. Is there anything I can do to get this behavior? As an FYI, we have gestures and other scroll views configured in the view and we don't want to loose these. It seems that the above code would take control over all touches within the view thus breaking our gestures and other scroll views.

    Thanks
Sign In or Register to comment.