I have a question that I’ve searched but can’t find a definative answer to. Here is my layout:
UIView - ViewController
|_UIScrollView - added programatically
| |_UIView to hold a backgound/perimeter - added programmatically
|_UIView 1 - added programmatically
|_UIView 2 - added programmatically
and so on
My question is how come the ViewController calls “touchesMoved” only once when I move say UIView 2 on touch?
Now UIView has it’s own touchesMoved method, but I need the controller’s touchesMoved to get called as I need it to talk to the ScrollView to update its position. Such as when that UIView 2 is near the corner, so that the ScrollView moves a little to fully show UIView 2.
If there is no way around this is there a way to update ScrollView from UIView 2 to scroll when its near a corner?
Edit:
I think I may have found a work around. Not sure if this will be accepted by Apple but:
I just made a call to a instance variable that is = to self.superview which then allows me to talk back to my ScrollView within UIView’s touchesMoved
in that i can call the method [ScrollView setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated] so my ScrollView gets updated as the subview(UIView2) moves close to the edge of the UIWindow.
Thank you for the suggestions.
The behavior you describe is the result of the
UIScrollViewhijacking the touch moved event. In other words, as soon as theUIScrollViewdetect that a touch moved event falls within its frame, it takes control of it. I experienced the same behavior while trying so create a special swipe handler, and it failed each time aUIScrollViewwas also interested by the swipe.In my case, I solved the issue by intercepting the event in
sendEvent:overridden in my customUIWindow, but I don’t know if you want to do the same. In any case, this is what worked for me:An alternative approach that you might investigate is attaching a gesture recognizer to your views — they have a pretty high priority, so maybe the UIScrollView will not mess with them and it might work better for you.
Have you tried to make the
UIScrollViewscroll by calling: