gpt4 book ai didi

iphone - 从 appdlication 中的缓存目录加载图像在 App 委托(delegate)中完成方法

转载 作者:行者123 更新时间:2023-11-28 19:12:19 28 4
gpt4 key购买 nike

我试图在启动图像消失后加载图像。所以我想在应用程序中添加一个 ImageView 到 self.window 完成启动方法。我从缓存目录中选择图像。但它在加载之前显示空白屏幕 Root View Controller 。我怎样才能实现这个这是我的代码,用于将图像添加到 imageview,然后将 ImageView 作为 subview 添加到 self.window....

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@""];
imgView.frame=CGRectMake(0, 0, 768, 1024);

NSString *URLImg = [documentsDirectory stringByAppendingPathComponent:@"SplashIpad.png"];
UIImage *imgAvtar = [[UIImage alloc]initWithContentsOfFile:URLImg];
[imgView setImage:imgAvtar];
[self.window addSubview:imgView];

请建议我如何在启动画面关闭后加载图像。

最佳答案

按照您的逻辑和代码,您可以这样做:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[clsViewController alloc] initWithNibName:@"clsViewController" bundle:nil] autorelease];



NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@""];
NSLog(@"do ==%@",documentsDirectory);

NSString *URLImg = [documentsDirectory stringByAppendingPathComponent:@"index.jpg"];

NSLog(@"==%@",URLImg);
UIImage *imgAvtar = [[UIImage alloc]initWithContentsOfFile:URLImg];

UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)];
[imgView setImage:imgAvtar];
imgView.center=self.viewController.view.center;

// UIImage *imgAvtar = [UIImage imageNamed:@"index.jpg"];

[self.viewController.view addSubview:imgView];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

Screen Shot:-

演示链接:在演示中,我从 NSBundal 获取图像,但您可以在 didFinishLaunchingWithOptions 方法中使用我的上述逻辑

http://www.sendspace.com/file/8srobj

注意:-

确保在 /iPhone Simulator/6.0/Applications/8886B938-3EFB-4F0C-96F9-41ACAE508F2B/Library/Caches/index.jpg 路径中名为 index 的图像.jpg 放置在catch文件夹中

关于iphone - 从 appdlication 中的缓存目录加载图像在 App 委托(delegate)中完成方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14622688/

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