gpt4 book ai didi

iphone - iOS 代码显示白色区域而不是图像系列

转载 作者:行者123 更新时间:2023-11-29 13:39:59 25 4
gpt4 key购买 nike

下面的代码应该在无限连接循环中显示一系列图像。相反,它只是显示一个完全白色的区域。感谢 Aaron Hayman 让我走到这一步。

- (void)layoutScrollImages
{
//Arrangement
NSArray *imageViews = [NSArray arrayWithObjects:@"image1.png", @"image2.png", @"image3.png", nil];
CGRect cRect = scrollView1.bounds;
UIImageView *cView;
for (int i = 0; i < imageViews.count; i++)
{
cView = [imageViews objectAtIndex:i];
cView.frame = cRect;
[scrollView1 addSubview:cView];
cRect.origin.x += cRect.size.width;
}
scrollView1.contentSize = CGSizeMake(cRect.origin.x, scrollView1.bounds.size.height);
scrollView1.contentOffset = CGPointMake(scrollView1.bounds.size.width, 0); //should be the center page in a 3 page setup

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
scrollView1.contentOffset = CGPointMake(scrollView.bounds.size.width, 0);
}

跟进:

我所做的一切都没有任何改变。目前,我的代码看起来像这样,但我正在改变我能想到的一切都无济于事。

- (void)layoutScrollImages
{
//Horizontal arrangement
NSObject *image1 = @"image1.png";
NSObject *image2 = @"image2.png";
NSObject *image3 = @"image3.png";
NSArray *imageViews = [NSArray arrayWithObjects:image1, image2, image3, nil];
CGRect cRect = scrollView1.bounds;
UIImageView *cView;
for (int i = 0; i < imageViews.count; i++)
{
cView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[imageViews objectAtIndex:i]]];
cView.frame = cRect;
[scrollView1 addSubview:cView];
cRect.origin.x += cRect.size.width;
}
scrollView1.contentSize = CGSizeMake(cRect.origin.x, scrollView1.bounds.size.height);
scrollView1.contentOffset = CGPointMake(scrollView1.bounds.size.width, 0); //should be the center page in a 3 page setup

[self layoutScrollImages];

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
scrollView1.contentOffset = CGPointMake(scrollView.bounds.size.width, 0);
}

最佳答案

您永远不会启动 UIImageView。你想做这样的事情:

        NSArray *imageViews = [NSArray arrayWithObjects:@"image1.png", @"image2.png", @"image3.png", nil];
CGRect cRect;
UIImageView *cView;
for (int i = 0; i < imageViews.count; i++)
{
cView = [[UIImageView alloc] initWithImage:[UIImage imageName:[imageViews objectAtIndex:i]]];
cRect = cView.frame;
cRect.origin.x += scrollView1.frame.size.width;
cView.frame = cRect;
[scrollView1 addSubview:cView];
NSLog(@"imageView bounds: %@", NSStringFromCGRect(cView.frame));
}

编辑:尝试上面的操作,看看是否有任何显示。以下是一些想法:

  1. 您确定没有将 imageView 设置为 0 高度/宽度吗?我在循环中加入了一个 NSLog 语句。它将打印 imageView 的框架。
  2. 您是否尝试过将图像添加到 self.view 而不是 scrollView1?这将是确保问题与 scrollView1 的框架无关的好方法。或者使用以下内容:NSLog(@"imageView bounds: %@", NSStringFromCGRect(scrollView1.frame));

关于iphone - iOS 代码显示白色区域而不是图像系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9450014/

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