如何设置两个嵌套UIImageViews的UIScrollView?

时间:2011-03-04 21:19:30

标签: iphone uiscrollview uiimageview overwrite

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

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

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

如果我只是为第一个scrollView执行代码,我会得到图像。所以就像我以某种方式通过包含第二个来覆盖第一个?

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

谢谢

1 个答案:

答案 0 :(得分:0)

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

第二个应该是imageView31