0

我有一个例子,当应用程序启动时我有动画。开始时会显示一个图像,然后从右向左移动,然后消失。下面是我的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewwController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewwController;
    [self.window makeKeyAndVisible];


    //add the image to the forefront...
    UIImageView *splashImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [splashImage setImage: [UIImage imageNamed:@"Default"]];
    [self.window addSubview:splashImage];
    [self.window bringSubviewToFront:splashImage];


    //set an anchor point on the image view so it opens from the left
    splashImage.layer.anchorPoint = CGPointMake(0, 0.5);

    //reset the image view frame
    splashImage.frame = CGRectMake(0, 0, 320, 480);

    //animate the open
    [UIView animateWithDuration:1.0
                          delay:0.6
                        options:(UIViewAnimationCurveEaseOut) 
                     animations:^{

                         splashImage.layer.transform = CATransform3DRotate(CATransform3DIdentity, -M_PI_2, 0, 1, 0);
                     } completion:^(BOOL finished){

                         //remove that imageview from the view
                         [splashImage removeFromSuperview];
                     }];

    return YES;

}

我想要的是使用情节提要来做到这一点,所以我将代码更改如下。

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MyBookViewController *myNew = [[MyBookViewController alloc] init];
self.myBookViewController = myNew;
self.window.rootViewController = self.myBookViewController;
[self.window makeKeyAndVisible];

但是我没有看到我的视图控制器(MyBookViewController)。我只看到图像从右向左移动,然后是黑屏。

知道出了什么问题吗?

4

2 回答 2

3

我只是在 的帮助下自己完成的this SO question

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                         bundle: nil];
MyBook001ViewController *controller = (MyBook001ViewController*)[mainStoryboard
                                                                             instantiateViewControllerWithIdentifier: @"firstStory"];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible];
于 2013-01-30T08:35:37.400 回答
0

我认为这是因为您正在分配新的 MyBookViewController。相反,您必须提供情节提要的参考,在上面您有 MyBookViewController 的 UI 设计,就像这样

MyBookViewController *myNew=[self.storyboard instantiateViewControllerWithIdentifier:@"MyBookViewController"];

确保 ViewController 标识符

更新1:

尝试

MyBookViewController *myNew=[self.window.rootViewController];
于 2013-01-22T08:55:17.233 回答