gpt4 book ai didi

iphone - 我有一个 ScrollView 缩放错误的 imageView 的问题

转载 作者:行者123 更新时间:2023-12-03 21:20:26 25 4
gpt4 key购买 nike

好吧,这是一个奇怪的问题,但我有两个 ScrollView ,每个 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 时,它会平移第二个 ScrollView 的图像,并缩放第一个 ScrollView 的图像。所以我的第二个 ScrollView 缩放了第一个 ScrollView 的图像。啊?我不知道为什么会发生这种情况。

我想要的只是必须分离可以独立平移和缩放的查看图像。

对可能发生的事情有什么想法吗?

谢谢!

最佳答案

您的 viewForZoomingInScrollView: 方法可能为两个 ScrollView 返回相同的 ImageView 。它需要查看传入的是哪个 ScrollView 并返回相应的 ImageView 。

关于iphone - 我有一个 ScrollView 缩放错误的 imageView 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5215776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com