0

以下是我的代码。我可以从我的 NSMutableArray 文件中加载所有图像文件,但它没有出现在我的屏幕上。我真的不知道为什么。如果有人可以帮助我,那就太好了。

提前致谢.....

UIImageView *bannerImages;
    CGRect bannerFrame;

    for (int photoCount = 0; photoCount < [imagesFileList count]; photoCount++)
    {
        NSLog(@"photoCount: %d",photoCount);

        bannerImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 340, 320, 80)];

        NSString *photoString = [NSString stringWithFormat:@"%@",[imagesFileList objectAtIndex:photoCount]];

        NSLog(@"photoString are: %@",photoString);

        bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];

        bannerFrame = bannerImages.frame;
        bannerFrame.origin.y = self.view.bounds.size.height;
    }

    [UIView animateWithDuration:1.0
                          delay:1.0
                        options: UIViewAnimationTransitionCurlDown
                     animations:^{
                         bannerImages.frame = bannerFrame;
                     }
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];

    [self.view addSubview:bannerImages];
    [bannerImages release];

这是我的日志文件显示:

2013-05-30 15:09:19.595 Yangon Guide Map[5035:15803] photoCount: 0
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv01.png
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoCount: 1
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv02.png
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoCount: 2
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv03.png
2013-05-30 15:09:19.597 Yangon Guide Map[5035:15803] photoCount: 3
2013-05-30 15:09:19.597 Yangon Guide Map[5035:15803] photoString are: edupro.png
2013-05-30 15:09:21.598 Yangon Guide Map[5035:15803] Done!
4

3 回答 3

0

我认为的问题是,您在 imageFileList 中填充了您在记录时获得的图像名称。

imageWithContentsOfFile不应该得到这样的图像

尝试

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:photoString ofType:@"png"]]];

或者

你可以使用imageNamed非常紧张的方法而不是这个

bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];

用这个

bannerImages.image = [UIImage imageNamed:photoString];
于 2013-05-30T09:18:52.953 回答
0

1.假设.png图像在 中App Bundle,您可以替换

bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];

bannerImages.image = [UIImage imageNamed:photoString]];

2. bannerFrame.origin.y = self.view.bounds.size.height;似乎没有帮助。

于 2013-05-30T08:59:45.887 回答
0

你真正想做的是什么?因为他们的代码中有很多错误......

1)你没有创建你的 UIImage -imageWithContentsOfFile: 不会找到你的文件,使用:

bannerImages.image = [UIImage imageNamed:photoString];

或者

bannerImages.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[imageNamed:photoString stringByDeletingPathExtension] ofType:@"png"]];

2)您为数组中的每个图像创建一个新的 UIImageView ,但只将最后一个添加到您的根视图中。在你的循环中添加你的每个 UIImageView :

for (int photoCount = 0; photoCount < [imagesFileList count]; photoCount++)
{
     bannerImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 340, 320, 80)];

     // Snip ...

[UIView animateWithDuration:1.0
                      delay:1.0
                    options: UIViewAnimationTransitionCurlDown
                 animations:^{
                     bannerImages.frame = bannerFrame;
                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

[self.view addSubview:bannerImages];
[bannerImages release];
}

3)您的bannerFrame 计算似乎也错误,因为您超出了您的超级视图范围,并且所有 UIImageView 都将具有相同的框架。你的超级视图是什么,一个 UIScrollView ?你想让我做什么 ?

于 2013-05-30T10:13:46.790 回答