ScrollView outside visible View
I try to create something similar to the task-menu in iOS4:
(Sorry cant post images not enough Rep)
I have normal ViewController on thats view 开发者_如何学Pythoni addSubview of my menuView. I set menuViews Y to -95 so i can just move the viewControllers view 95 Down to Display the menu. But the scrollView in my menuView doesn't work if the menuViews Y is Negative.
Your scrollview doesn't receive the touch input because it is outside the bounds of the its superview (the view of the main ViewController you mentioned). The way the touch interaction system works is the AppKit framework goes down the view hierarchy testing each view and subview with the - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event function. If a view returns YES to this function, it will start the process all over again with all of its subviews until it finds the lowest subview that still returns YES. The problem with your setup is that the superview of Scrollview is going to return NO because the touch is above it and your menuView never even gets tested. So you have two possible solutions:
Implement your ViewControllers view as a subclass of UIView (if it is not already) and overload the pointInside:withEvent: function to return YES if the touch is within it's frame OR if it is within the bounds of menuView (ViewControllers frame minus the frame of menuView).
The second solution would be to simply put menuView at the origin of its superview (0,0) and leave the ViewControllers view at (0,0) as well.
I suggest the second as it is less convoluted and more to the point.
精彩评论