gpt4 book ai didi

IOS:在 ScrollView 中添加一些子 ScrollView ,图像不出现

转载 作者:行者123 更新时间:2023-11-29 13:42:09 24 4
gpt4 key购买 nike

我有这个代码:

- (void)viewDidLoad
{
[super viewDidLoad];

NSArray *image = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"], [UIImage imageNamed:@"3.png"], nil];

for (int i = 0; i < image.count; i++) {
CGRect frame;
frame.origin.x = scrollV.frame.size.width * i;
frame.origin.y = 0;
frame.size = scrollV.frame.size;

UIScrollView *subScrollView = [[UIScrollView alloc] initWithFrame:frame];
UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];

[subview setImage:[image objectAtIndex:i]];
[subScrollView addSubview:subview];
[scrollV addSubview:subScrollView];
[subview release];
[subScrollView release];
}

scrollV.contentSize = CGSizeMake(scrollV.frame.size.width * image.count, scrollV.frame.size.height);

}

scrollV 是主 ScrollView ,它具有“启用分页”如果我使用这段代码,我的 scrollV 启用了分页,但我在第一页只看到它里面的“1.png”,我没有看到其他 png,为什么?

最佳答案

您将 subview 的框架设置为不正确的值。这使它与其 subScrollView 成为相同的框架,因此它将它推到右边。试试这个:

- (void)viewDidLoad
{
[super viewDidLoad];

NSArray *image = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"], [UIImage imageNamed:@"3.png"], nil];

for (int i = 0; i < image.count; i++) {
CGRect frame;
frame.origin.x = scrollV.frame.size.width * i;
frame.origin.y = 0;
frame.size = scrollV.frame.size;

UIScrollView *subScrollView = [[UIScrollView alloc] initWithFrame:frame];
UIImageView *subview = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height)];

UIImage *image = [image objectAtIndex:i];
subScrollView.contentSize = image.size;

[subview setImage:image];
[subScrollView addSubview:subview];
[scrollV addSubview:subScrollView];
[subview release];
[subScrollView release];
}

scrollV.contentSize = CGSizeMake(scrollV.frame.size.width * image.count, scrollV.frame.size.height);

}

编辑:也可能最好设置内部 ScrollView 的内容大小。我在上面添加了代码。

关于IOS:在 ScrollView 中添加一些子 ScrollView ,图像不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8787572/

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