嵌套的UIScrollViews。 尝试让其中一个以与另一个放大速度相同的速度和因子缩小。视图冻结

我正在尝试设置嵌套的UIScrollViews。 我有两个相同的内容大小640 * 640像这样设置的滚动视图:canvasScrollView( UIScrollView )> contentScrollView( UIScrollView )>内容( UIView )。 这些都在UIViewController 。 我想要发生的是,当用户捏放大contentScrollView中的内容时,canvasScrollView视图以相同的因子和速度缩小。 我已经尝试设置如下的代码:

 #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; } 

我的第一步是确保它是放大的contentScrollView而不是canvasScrollView。 与我的代码上面的意见加载正常,但我无法平移或缩放的内容。 我不知道为什么这不起作用。 我已经从用户交互禁用了canvasScrollView,因为稍后将以编程方式进行修改,我还设置了contentScrollView委托。 虽然没有工作。 会真的很感谢这一个帮助!

谢谢

您已将contentScrollView添加到具有userInteractionEnabled=NO的视图。 不允许用户交互的视图不允许用户交互其任何子视图。 尝试将其附加到self.view

 [self.view addSubview:contentScrollView];