gpt4 book ai didi

ios - 具有多个水平图像的 UIScrollView

转载 作者:行者123 更新时间:2023-11-29 01:25:38 24 4
gpt4 key购买 nike

我需要在 View 中水平滚动 2 个图像。我已经很好地实现了单个图像滚动,但无法在 ScrollView 中显示多个图像。我附上了单卷轴的代码。下面是我需要实现的附加图像。 enter image description here

galleryScrollView = [UIScrollView new];
galleryScrollView.pagingEnabled = YES;
galleryScrollView.backgroundColor = [UIColor clearColor];
galleryScrollView.translatesAutoresizingMaskIntoConstraints = NO;
galleryScrollView.showsHorizontalScrollIndicator = NO;
galleryScrollView.showsVerticalScrollIndicator = NO;
galleryScrollView.delegate = self;
galleryScrollView.scrollEnabled = YES;
[backView addSubview:galleryScrollView];

for(int i=0;i<resultDict.count;i++) {

CGRect frame;
frame.origin.x= galleryScrollView.frame.size.width *i;
frame.origin.y=0;
frame.size=galleryScrollView.frame.size;

UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.translatesAutoresizingMaskIntoConstraints = YES;
imageView.clipsToBounds = YES;

NSString *imageString = [[resultDict valueForKey:@"ImageURL"] objectAtIndex:i];
[imageView setImageWithURL:[NSURL URLWithString:imageString]];
[galleryScrollView addSubview:imageView];
}
galleryScrollView.contentSize=CGSizeMake(galleryScrollView.frame.size.width * resultDict.count, galleryScrollView.frame.size.height);

最佳答案

问题是你想要在一个屏幕上显示两个图像,但是你为每个图像制作的框架是屏幕的大小,并且原点是关闭的。要更改原点,请替换

frame.origin.x= galleryScrollView.frame.size.width *i;

frame.origin.x= galleryScrollView.frame.size.width *i/2;

同样,您还需要更改 frame.size

关于ios - 具有多个水平图像的 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34057955/

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