[英]UIImage didnt show on my screen
以下是我的代碼。 我可以從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!
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;
似乎沒有幫助。
我認為的問題是,您已在imageFileList中填充了在記錄時獲取的圖像名稱。
imageWithContentsOfFile
不應該這樣獲得圖像
嘗試
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:photoString ofType:@"png"]]];
要么
您可以使用imageNamed
methiod,它非常容易向前移動,因此可以使用它
bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];
用這個
bannerImages.image = [UIImage imageNamed:photoString];
你到底想干什么? 因為它們在您的代碼中有很多錯誤...
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? 你想讓我做什么 ?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.