0

I have an example where I have animation when the app starts. At the start an image is displayed, then moves from right to left, then disappears. Below is the code I have.

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

}

What I want is to do this using a storyboard, so I changed the code as below.

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];

However I don't see my viewcontroller (MyBookViewController). I only see the image moving from right to left, then a black screen.

Any idea what is going wrong?

CloudyMarble
  • 34,949
  • 69
  • 92
  • 126
Fahim Parkar
  • 28,922
  • 40
  • 153
  • 260

2 Answers2

3

I just did it myself with help of 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];
Community
  • 1
  • 1
Fahim Parkar
  • 28,922
  • 40
  • 153
  • 260
  • I think since the addition of storyboards there is more of a trend to create less code. That said, I would have declared the `Main storyboard file base name` (aka UIMainStoryboardFile) in your Info.plist file for the target you're working with. Then I would have created a class linked to a view (your splash screen) to animate out of view and push a new view to the user. Perhaps you'll like this implementation better? Just an option... – Alex Smith Feb 05 '13 at 11:19
0

i think it is because of you are allocating new MyBookViewController. instead it you have to give reference of storyboard, on which you have your UI design for MyBookViewController, like this

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

be sure for ViewController identifier

UPdate1:

try with

MyBookViewController *myNew=[self.window.rootViewController];
Ravindra Bagale
  • 16,225
  • 9
  • 38
  • 68