Nested UIScrollViews. Trying to get one to zoom out with the same speed and factor as the other zooming in. View frozen

↘锁芯ラ 提交于 2019-12-23 05:32:07

问题


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


回答1:


You have added contentScrollView to a view that has userInteractionEnabled=NO. A view that doesn't allow user interaction does not allow user interaction any of its subviews. Try attaching it to the self.view instead.

[self.view addSubview:contentScrollView];


来源:https://stackoverflow.com/questions/28219433/nested-uiscrollviews-trying-to-get-one-to-zoom-out-with-the-same-speed-and-fact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!