0

我试图在启动图像消失后加载图像。所以我想在应用程序中向 self.window 添加一个图像视图确实完成了启动方法。我从缓存目录中选择图像。但是它在加载 rootview 控制器之前显示一个空白屏幕. 我该如何实现这是我将图像添加到 imageview 的代码,然后将图像视图添加到 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];

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

4

2 回答 2

4

作为你的逻辑和代码,你可以这样做: -

- (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;
}

截屏:-

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

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

笔记:-

确保在捕获文件夹中具有 palce/iPhone Simulator/6.0/Applications/8886B938-3EFB-4F0C-96F9-41ACAE508F2B/Library/Caches/index.jpg名称的图像路径index.jpg

于 2013-01-31T10:01:10.197 回答
0

它可能会帮助您。使用 UIViewController 并在其中获取图像视图(从缓存目录加载图像)。在 appdelegate 中将 viewcontroller 添加到 window 。如果你没有得到我,请告诉我。

于 2013-01-31T09:51:49.817 回答