嵌套的 UIScrollViews.试图让一个以与另一个放大相同的速度和系数缩小.视图冻结 [英] Nested UIScrollViews. Trying to get one to zoom out with the same speed and factor as the other zooming in. View frozen

查看:18
本文介绍了嵌套的 UIScrollViews.试图让一个以与另一个放大相同的速度和系数缩小.视图冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的第一步是确保缩放的是 contentScrollView 而不是 canvasScrollView.使用上面的代码,视图可以正常加载,但我无法平移或缩放内容.我不确定为什么这不起作用.我已经从用户交互中禁用了 canvasScrollView,因为稍后将以编程方式对其进行修改,我还设置了 contentScrollView 委托.虽然不工作.真的很感谢这方面的一些帮助!!!

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!!!

谢谢

推荐答案

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

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];

这篇关于嵌套的 UIScrollViews.试图让一个以与另一个放大相同的速度和系数缩小.视图冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆