我有一个问题与scrollView缩放错误的imageView

时间:2011-03-07 04:17:51

标签: iphone view uiscrollview uiimageview zoom

好的,所以这是一个奇怪的问题,但我有两个scrollView,每个都有一个嵌套的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];

}

没有缩放,当我捏缩放第一个scrollView / imageView对时,它工作得很漂亮,没有任何问题。它放大并没有问题。但是,当我捏​​缩放我的第二个scrollView时,它会扫描SECOND的图像,并缩放FIRST的图像。所以我的第二个scrollView缩放了FIRST的图像。咦?我不知道为什么会发生这种情况。

我想要的只是分开可以独立平移和缩放的图像。

有关可能发生的事情的任何想法?

谢谢!

1 个答案:

答案 0 :(得分:1)

您的viewForZoomingInScrollView:方法可能会为两个滚动视图返回相同的图像视图。它需要查看传入的滚动视图并返回相应的图像视图。