I am going to attach an application that I made. It passes touches in UIScrollView to subviews.
Using IB, I made the following:
Window
-View
--UIScrollView
---UIView (*contentView)
----MyImageView
----UIButton
I had to make the AppDelegate the UIScrollView delegate. Within the AppDelegate I implemented the zoom view method.
Code:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return contentView;
}
Since the UIImage and UIButton are subviews of the UIView, they scroll and zoom together.
UIButton's touch up inside method can be linked to an IBAction. In this case I linked it to a method in the appDelegate that prints an NSLog line.
I had to subclass UIImageView (MyImageView) to implement a touches method:
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"ImagePressed");
}
I had to check UserInteractionEnabled for the contentView, MyImageView, and the UIButton.
Note however that I did not have to use ThirtyOne's code. I did not have to subclass UIScrollView. It seems as though the documentation is telling the truth in that UIScrollView passes touches to the subviews by default. (Look for touchesShouldBegin in the documentation).
Also note that touches are passed immediately when zoomed all the way out (no scrolling possible). But when zoomed in some, touches only pass after a short delay (to make sure the touch isn't a scroll).
I made this with IB in 10 minutes. I am trying to get this to work using view controllers and programming my view hierarchy manually, but have not been successful yet.