How to pass touches from UIView to UIScrollView?

If it were me, I would set the scrollView as the top view's delegate. This, of course, would require that the top view is a custom sublcass of UIView so you can set.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

Similar to this thread and many others, I've got a view controller with a NIB file which has this layout... a. UIView (480 x 320) - stores a background image b. UIScrollView (480 x 220) - Is a level selector scrollview c.

UIView (480 x 320) - contains a foreground animated graphic All three items above are subviews of the main View in the NIB. UIView (c) is the full size of the iPhone screen and on top of the hierarchy. On it, I've placed a character which animates based on the current touch position in that view.

However the issue is that with this view receiving touches, I cannot get the touches to the ScrollView (b) below it. I still need to use the touches at (c) but also need to pass relevant touches / swipes to the UIScrollView below afterwards. Can anyone advise how this can be done?

I've read various posts on using hittest but don't want to offset the touches completely, I just need to forward them after so that the scrollview still works as normal. Thanks, iphone objective-c uiview uiscrollview link|improve this question edited Sep 20 '11 at 17:12 asked Sep 20 '11 at 16:31Simon1,55248 78% accept rate.

If it were me, I would set the scrollView as the top view's delegate. This, of course, would require that the top view is a custom sublcass of UIView, so you can set id delegate; and @property (nonatomic, assign) id delegate; in the header file. You would then set the scrollView as the delegate with something along the lines of topView setDelegate:scrollView; With this in place, you can then send messages (in your case, touch events) to the scrollView when they are necessary.

If, for example, you want to send all touchBegan events, you would have this: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { self. Delegate touchesBegan:touches withEvent:event; } Of course, if you only want certain events passed, you would set up your parameters in the methods to say when to call self. Delegate .... or super ..... The latter will perform the action for the view rather than in the scrollView.

I hope this helps.

The problem with this, is that swipes aren't detected in the scrollview - I tried this method earlier before I got to the 'state' I'm in now. Lol... and it IS a state! However you did get me thinking about passing the information required to animate, but without the touch events.

I shall look into this! – Simon Sep 20 '11 at 17:24 Haha, I know that feeling all too well. But I am glad this got you thinking of new ways to go about the problem.

This is usually my default for issues like that. Basically just set up the conditions in which to send events to the delegate and go from there, whether it be gestures or touches or something else. If you need more control, you can subclass the scrollView and adopt a custom protocol from the top view that specifies what methods to call and how to implement them.

I hope that isn't confusing, but if that's something you might want to try, I'd be more than happy to help – slev Sep 20 '11 at 17:30 Yeah, this is certainly a design issue - I always know when I'm doing something a silly way because it 'feels' like bad programming! Appreciate your suggestions though. – Simon Sep 20 '11 at 17:36 No problem.

I'm always glad to help. I hope you get everything fixed up soon. – slev Sep 20 '11 at 17:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions