我有一个滚动视图缩放错误的图像视图的问题
Posted
技术标签:
【中文标题】我有一个滚动视图缩放错误的图像视图的问题【英文标题】:I have a problem with a scrollView zooming the wrong imageView 【发布时间】:2011-03-07 04:17:50 【问题描述】:好的,这是一个奇怪的问题,但我有两个滚动视图,每个都有一个嵌套的 imageView,以便平移和缩放图像。拖曳 scrollView/imageView 组合显示得非常好,而且因为图像比我的 scrollView 尺寸大,所以我可以平移得很好。这是我的 viewDidLoad:
-(void) viewDidLoad
// set the image to be displayed, pic your own image here
imageView = [[MyImage alloc] initWithImage: [UIImage imageNamed: @"newBackground.png"]];
// yes we want to allow user interaction
[imageView setUserInteractionEnabled:YES];
// set the instance of our myScrollView to use the main screen
scrollView = [[MyScroll alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
// turn on scrolling
[scrollView setScrollEnabled: YES];
// set the content size to the size of the image
[scrollView setContentSize: imageView.image.size];
// add the instance of our myImageView class to the content view
[scrollView addSubview: imageView];
// flush the item
[imageView release];
// set max zoom to what suits you
[scrollView setMaximumZoomScale:1.0f];
// set min zoom to what suits you
[scrollView setMinimumZoomScale:0.25f];
// set the delegate
[scrollView setDelegate: self];
// scroll a portion of image into view (my image is very big) :)
//[scrollView scrollRectToVisible:CGRectMake(100, 100, 320, 440) animated:NO];
// yes to autoresize
scrollView.autoresizesSubviews = YES;
// set the mask
scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
// set the view
//self.view =scrollView;
[scrollView setFrame:CGRectMake(0, 0, 320, 230)];
[self.view addSubview:scrollView];
imageView1 = [[MyImage alloc] initWithImage: [UIImage imageNamed: @"newBackground.png"]];
// yes we want to allow user interaction
[imageView1 setUserInteractionEnabled:YES];
// set the instance of our myScrollView to use the main screen
scrollView1 = [[MyScroll alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
// turn on scrolling
[scrollView1 setScrollEnabled: YES];
// set the content size to the size of the image
[scrollView1 setContentSize: imageView1.image.size];
// add the instance of our myImageView class to the content view
[scrollView1 addSubview: imageView1];
// flush the item
[imageView1 release];
// set max zoom to what suits you
[scrollView1 setMaximumZoomScale:1.0f];
// set min zoom to what suits you
[scrollView1 setMinimumZoomScale:0.25f];
// set the delegate
[scrollView1 setDelegate: self];
// scroll a portion of image into view (my image is very big) :)
//[scrollView scrollRectToVisible:CGRectMake(100, 100, 320, 440) animated:NO];
// yes to autoresize
scrollView1.autoresizesSubviews = YES;
// set the mask
scrollView1.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
// set the view
//self.view =scrollView;
[scrollView1 setFrame:CGRectMake(0,240,320,230)];
[self.view addSubview:scrollView1];
//[[self view] addSubview:scrollView];
不至于缩放,当我捏放大第一个滚动视图/图像视图对时,它工作得很好,没有任何问题。它缩放和平移没有问题。但是当我捏缩放我的第二个滚动视图时,它会平移第二个的图像,并缩放第一个的图像。所以我的 SECOND scrollView 缩放了 FIRST 的图像。嗯?我不知道为什么会这样。
我想要的只是分离可以独立平移和缩放的查看图像。
对可能发生的事情有什么想法吗?
谢谢!
【问题讨论】:
【参考方案1】:您的viewForZoomingInScrollView:
方法可能为两个滚动视图返回相同的图像视图。它需要查看传入的是哪个滚动视图,并返回对应的图像视图。
【讨论】:
以上是关于我有一个滚动视图缩放错误的图像视图的问题的主要内容,如果未能解决你的问题,请参考以下文章