I am trying to set up nested UIScrollViews. What I have is two scroll views with the same content size 640*640 setup like this: canvasScrollView (a UIScrollView
) > contentScrollView (a UIScrollView
) > content (a UIView
). These are all in a UIViewController
. What I want to happen is, when the user pinches to zoom in on the content in contentScrollView the canvasScrollView view zooms out at with same factor and speed. I have tried setting up code like below:
#import "ViewController.h"
#import "ContentView.h"
@interface ViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *canvasScrollView;
@property (strong, nonatomic) UIView *viewForZoom;
@property (strong, nonatomic) ContentView *content;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
contentScrollView.contentSize=CGSizeMake(640 ,640);
contentScrollView.minimumZoomScale=0.25;
contentScrollView.maximumZoomScale=1;
self.content = [[[NSBundle mainBundle] loadNibNamed:@"floatingView" owner:self options:nil] objectAtIndex:0];
self.viewForZoom=self.content;
[contentScrollView addSubview:self.content];
contentScrollView.delegate=self;
//canvasScrollView was setup in the interface builder, same dimensions as above 320*568
self.canvasScrollView.contentSize=CGSizeMake(640 ,640);
self.canvasScrollView.minimumZoomScale=0.25;
self.canvasScrollView.maximumZoomScale=1;
self.canvasScrollView.userInteractionEnabled=NO;
[self.canvasScrollView addSubview:contentScrollView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.viewForZoom;
}
My first step is to make sure it is the contentScrollView that zooms and not the canvasScrollView. With my code above the views load up fine but I am unable to pan or zoom the content. I'm not sure why this doesn't work. I have disabled the canvasScrollView from user interaction as later on this will be modified programmatically, I have also set the contentScrollView delegate. Not working though. Would really appreciate some help on this one!!!
Thanks