1

好的,我们都知道在滚动视图中嵌套图像视图可以让您拥有可以捏合和缩放的图像。很酷。我想复制这个(最终是四倍)功能。

在 IB 中,我并排设置了我的 2 个滚动视图,并在其中嵌套了 imageViews,并将它们连接到正确的变量和所有内容。

在我的 viewController viewDidLoad 里面我这样做:

[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.clipsToBounds = NO;    // default is NO, we want to restrict drawing within our scrollview
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 5;
scrollView.delegate = self;
[scrollView setScrollEnabled:YES];

imageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"monitor.JPG"]];

[scrollView addSubview:imageView3];
//[scrollView setFrame:CGRectMake(0, 0, 1024, 660)];


[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.clipsToBounds = NO;    // default is NO, we want to restrict drawing within our scrollview
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;

scrollView1.minimumZoomScale = 1;
scrollView1.maximumZoomScale = 5;
scrollView1.delegate = self;
[scrollView1 setScrollEnabled:YES];

imageView31 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"monitor.JPG"]];

[scrollView1 addSubview:imageView3];

看起来这应该可以正常运行。但是当我构建运行时发生的事情是非常不寻常的。我的第一个滚动视图应该在哪里只有一个空白背景,然后第二个滚动视图在那里有它的图像......

如果我只是为第一个滚动视图编写代码,我会得到图像。所以这就像我以某种方式通过包含第二个来覆盖第一个?

我真的无法理解这种行为是如何发生或为什么发生的。也许我做错了,我错过了什么?有没有人对如何实现这个多滚动视图视图有任何想法?

谢谢

4

1 回答 1

0
[scrollView addSubview:imageView3];
[scrollView1 addSubview:imageView3];

第二个应该是 imageView31

于 2011-03-04T21:22:36.277 回答