开发者

How can I setup two UIScrollViews that have nested UIImageViews?

开发者 https://www.devze.com 2023-02-15 09:36 出处:网络
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.

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 imageV开发者_如何转开发iews 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


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

The second one should be imageView31

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号