简体   繁体   中英

How to make UIScrollView forward touches to UIView subclass subview?

I have a UIScrollView which I'm using as a container for two 'pages' of views. The first page contains two subviews: a kind of 'canvas' UIView subclass that the user can paint on with touches, and a 'control panel' UIView subclass full of UIControls. The scroll view itself has scrolling disabled (I'm using a UIPageControl to scroll it.)

The problem is this: when I tap on any of the controls in the control panel view they work fine. However, when I touch the canvas view, nothing happens. There are no controls on the canvas subview; it's just an empty UIView subclass that detects touches and draws points under the user's finger. (Previously this was all working fine; I've just recently put the two pieces in the scroll view.)

How can I tell the UIScrollView to forward touches to the canvas subview? I have set the scrollview so that Delays Content Touches and Cancellable Content Touches are off. User Interaction Enabled and Multiple Touch are both on.

I do not know whether to subclass the UIScrollView and change it's touch handling, or whether to override some other method in the canvas UIView subclass.

EDIT: Vince (commenter) prompted me to look at where the touch event handlers lived. They exist in the UIViewController subclass which owns the control panel view and the canvas view (and, now, the scroll view.) touchesBegan isn't being called anymore.

Thanks

Are you using iOS 5? If so, try making use of the UIViewController Container APIs. If you have a ViewController with the UIScrollView and "child" view controller under it, you may linking issues. Try calling [self addChildViewController:theCanvasVC] in your controller for the scrollView.

I'm guessing at your architecture so i may be off. Let me know how your app is organized.

You can read up on Container View Controllers here . Scroll down to "Implementing a Container View Controller".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM