gpt4 book ai didi

objective-c - 无法一张一张地显示UIImage

转载 作者:行者123 更新时间:2023-11-28 23:03:52 24 4
gpt4 key购买 nike

从今天早上开始,我就有点卡住了……我试图在一张图片后加载另一张图片,但是……它不起作用……我什至没有显示我的第一张图片……

这是我的代码:

- (void) checkResources
{

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *manager = [NSFileManager defaultManager];
NSDirectoryEnumerator *direnum = [manager enumeratorAtPath:bundleRoot];


NSString *cuttedName;
NSString *cuttedName1;



for (NSString *path in direnum)
{

if ([[path pathExtension] isEqualToString:@"mp4"])
{
cuttedName1 = [path stringByReplacingOccurrencesOfString:@"ressources/" withString:@""];
cuttedName = [cuttedName1 stringByReplacingOccurrencesOfString:@".mp4" withString:@""];
if ([cuttedName isEqualToString:[NSString stringWithFormat:@"%d", num]])
{
NSString *media = [NSString stringWithFormat:@"%@/%@", bundleRoot, path];
[self startSlideShow:media];
}
}
else if ([[path pathExtension] isEqualToString:@"mov"])
{
cuttedName1 = [path stringByReplacingOccurrencesOfString:@"ressources/" withString:@""];
cuttedName = [cuttedName1 stringByReplacingOccurrencesOfString:@".mov" withString:@""];
if ([cuttedName isEqualToString:[NSString stringWithFormat:@"%d", num]])
{
NSString *media = [NSString stringWithFormat:@"%@/%@", bundleRoot, path];
[self startSlideShow:media];
}
}
else if ([[path pathExtension] isEqualToString:@"png"])
{
cuttedName1 = [path stringByReplacingOccurrencesOfString:@"ressources/" withString:@""];
cuttedName = [cuttedName1 stringByReplacingOccurrencesOfString:@".png" withString:@""];
if ([cuttedName isEqualToString:[NSString stringWithFormat:@"%d", num]])
{
NSString *media = [NSString stringWithFormat:@"%@/%@", bundleRoot, path];
num++;
[self startImage:media];
}
}
}

}
- (void) startImage:(NSString *)nameFile
{
CGRect myImageRect = CGRectMake(0, 0, 200, 500);

UIImageView *imageView;
imageView = [[UIImageView alloc] initWithFrame:myImageRect];
[imageView setImage:[UIImage imageNamed:@"0.png"]];
NSLog(@"IAMGE %@", imageView.image);
[self.view addSubview:imageView];
[self performSelector:@selector(checkResources) withObject:nil afterDelay:10]; // this will give time for UI to update itself..
[imageView release];

}

- (void) startSlideShow:(NSString *)nameFile
{
NSURL *url = [NSURL fileURLWithPath:nameFile];//[[NSBundle mainBundle] pathForResource:@"2" ofType:@"mov"]];




MPMoviePlayerController *moviePlayer =
[[MPMoviePlayerController alloc] initWithContentURL:url];
// NSLog(@" URL : %@", url);

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.view.frame = CGRectMake(0, 0, 500, 600);

moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}



-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
MPMoviePlayerController *moviePlayer = [notification object];

[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
{
// [moviePlayer.view removeFromSuperview];
}


//[[moviePlayer release] addAnimation:animation forKey:kCATransition];


num++;
[self checkResources];
}

不要介意我的代码的目标 :) 我只想显示 uiimage,然后在显示第一张图像后调用方法 checkResources 时,我将向 startImage 发送另一张图像。

最佳答案

您的代码中可能存在两个主要问题……没有其他问题。

1) 由于连续的 addSubview 方法,您的 UI 没有更新..

2) 你的 UIImage 是空的..

检查1)

改变

[self checkResources];

[self performselector:@selector(checkResources) withObject:nil afterDelay:3] // this will give time for UI to update itself.. 

对上面的代码使用自动完成...可能是拼写错误..

检查2)

简单地 NSlog imageview.image .. 这将判断 ImageView 图像是否为空..

关于objective-c - 无法一张一张地显示UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9619164/

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