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

发布于 2024-10-20 12:45:40 字数 1526 浏览 2 评论 0原文

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

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

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

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

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

我真的不明白这种行为是如何或为何发生的。也许我的做法全错了,我错过了什么?有谁对如何实现这个多滚动视图视图有任何想法吗?

谢谢

Ok we all know that nesting an image view inside of a scroll view allows you to have an image that you can pinch and zoom. Pretty cool. I want to duplicate this (eventually quadruple) feature.

In IB I have setup my 2 scroll views side by side, and have nested imageViews inside of them and have hooked them up to the proper variables and everything.

Inside of my viewController viewDidLoad I do this:

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

It seems like this should run ok. But is what happens when I build in run is quite unusual. There is just a blank background for where my first scroll view should be and then the second scrollView has its image in there...

If I just do the code for the first scrollView, I get the image. So it's like I am somehow overwriting the first by including the second?

I really can't understand how or why this behavior is occurring. Maybe I am going about it all wrong, what am I missing? Does anyone have any ideas as to how to implement this multiple scrollView view?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蛮可爱 2024-10-27 12:45:40
[scrollView addSubview:imageView3];
[scrollView1 addSubview:imageView3];

第二个应该是imageView31

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

The second one should be imageView31

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文