gpt4 book ai didi

ios - 在启用分页和滚动的 uiscrollview 中启用缩放

转载 作者:可可西里 更新时间:2023-11-01 05:34:13 26 4
gpt4 key购买 nike

我有一个 uiscrollview,我加载了一组图像,以便我可以滚动浏览图片,效果类似于 IOS 中的照片效果。我正在使用这段代码:

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
NSString *imageFilePath = [path stringByAppendingPathComponent:@"newPics"];
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imageFilePath];
if(fileExists){

imgs=[[NSMutableArray alloc]init];


[imgs addObject:[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:@"newPics/pic1.png"]]];
[imgs addObject:[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:@"newPics/pic2.png"]]];
[imgs addObject:[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:@"newPics/pic3.png"]]];
[imgs addObject:[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:@"newPics/pic4.png"]]];


CGSize imageSize;
imageSize.height = 648;
imageSize.width = 927;
self.scroll1.frame = CGRectMake(0,0,imageSize.width,imageSize.height);

self.scroll1.contentSize = CGSizeMake(imageSize.width * imgs.count, imageSize.height );
self.scroll1.minimumZoomScale=1.0;
self.scroll1.maximumZoomScale=3.0;
self.scroll1.pagingEnabled = YES;


self.scroll1.delegate=self;

CGFloat xPos = 0.0;

for (UIImage *image in imgs) {
imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(xPos, 0.0, imageSize.width, imageSize.height);
[self.scroll1 addSubview:imageView];
xPos += imageSize.width;

}


}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
int positionScrollPrim = scrollView.contentOffset.x;

int positionScroll = positionScrollPrim / 927 ;

imageView = [[UIImageView alloc] initWithImage:[imgs objectAtIndex:positionScroll]];
//UIImage *tmep = [imgs objectAtIndex:1];

return imageView;
}

我无法获得正确的结果,相反我得到了一堆奇怪的行为,例如不正确的缩放以及当我尝试缩放时不再滚动。我想我的问题出在 viewForZoomingInScrollView 部分,这就是我尝试使用上面的代码解决它的原因。但我就是无法让它发挥作用。我错过了什么?

最佳答案

常用的方法是使用两个 ScrollView :外面的一个滚动浏览图像,每个图像都包裹在另一个负责缩放的 ScrollView 中。

关于ios - 在启用分页和滚动的 uiscrollview 中启用缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26274026/

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