Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
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 :)
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.
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 :)
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 :)
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.
// 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 :)
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.
// 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.
rocotilosPosts: 3,216iPhone Dev SDK Supporter, Registered Users
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.
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.
// 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 :)
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.
Replies
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.
iPhone development tips and tutorials
Apps in store:
<a href="htt
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeUnfortunately 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 :)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAfter 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 :)
iPhone development tips and tutorials
Apps in store:
<a href="htt
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeTo 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 :)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHello, could you give us more information about this? I tried to do teh same but without success.
Thanks
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI 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.
10 Detailed Steps to Submit Apps To AppStore
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome