Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-02-2012, 03:22 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default presentModalViewController doesn't work on app launch

I want a modal view controller to be "preloaded" and displaying onscreen when the app starts, so I can have the company logo showing up and then slide offscreen (the disappearing animation of the "cover vertical" transition) after 2 seconds. So, I have the launch image set to the company logo graphic (fills the entire iPad screen), and I am trying to get it so that when the launch image disappears, there's another copy of the image behind it as a modal view controller.

But for some reason, unless I put the call to presentModalViewController in viewDidAppear, the method just doesn't do anything. Here's my code:

(IntroSplashViewController has a view with a single image view, the company logo)

Code:
        IntroSplashViewController *isvc = [[IntroSplashViewController alloc] init];
        [isvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentModalViewController:isvc animated:NO];
        [isvc release];
        
        NSLog(@"Modal View Controller: %@ isvc: %@",self.modalViewController,isvc);
        
        [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(dismissSplashScreen) userInfo:nil repeats:NO];
dismissSplashScreen just has dismissModalViewController in it.

When placed in any method aside from viewDidAppear, the NSLog logs:

Quote:
Modal View Controller: (null) isvc: <IntroSplashViewController: 0x151a90>
If I do put it in viewDidAppear, I see the main part of the app for a second before the splash screen (modal view controller) pops up...help?
__________________
HEY! Was this post helpful?
If so, it would be MUCH appreciated if you'd just click on one of these apps:



MyD
Take 1 minute to set up your MyD and you'll always be able to prove you own your device!

Membrik
Test your memory by sliding tiles to match chains of increasing difficulty.

©2011 Dardom Productions | Like us on Facebook!
SoulRed12 is offline   Reply With Quote
Old 02-02-2012, 08:56 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by SoulRed12 View Post
I want a modal view controller to be "preloaded" and displaying onscreen when the app starts, so I can have the company logo showing up and then slide offscreen (the disappearing animation of the "cover vertical" transition) after 2 seconds. So, I have the launch image set to the company logo graphic (fills the entire iPad screen), and I am trying to get it so that when the launch image disappears, there's another copy of the image behind it as a modal view controller.

But for some reason, unless I put the call to presentModalViewController in viewDidAppear, the method just doesn't do anything. Here's my code:

(IntroSplashViewController has a view with a single image view, the company logo)

Code:
        IntroSplashViewController *isvc = [[IntroSplashViewController alloc] init];
        [isvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [self presentModalViewController:isvc animated:NO];
        [isvc release];
        
        NSLog(@"Modal View Controller: %@ isvc: %@",self.modalViewController,isvc);
        
        [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(dismissSplashScreen) userInfo:nil repeats:NO];
dismissSplashScreen just has dismissModalViewController in it.

When placed in any method aside from viewDidAppear, the NSLog logs:



If I do put it in viewDidAppear, I see the main part of the app for a second before the splash screen (modal view controller) pops up...help?
The method presentModalViewController presents a modal view controller on top of the current view controller. If the current view controller isn't set up yet, it doesn't work.

What we've done is to add a view on top of the app's first view controller that completely covers the screen. Make it a UIImageView, and install the image you want into it. You can even use your default.png file, to make the splash screen last a little longer (don't overdo it, though. Apple will reject your app for displaying a splash screen for too long.)

Then in your root view controller's viewDidLoad method, use animateWithDuration:delayptions:animations:compl etion: to animate away your view. Something like this:


Code:
- (void)viewDidLoad
{
  //Add an instance variable "splashAlreadyHidden" to your view controller, so you only animate the splash
  //screen once on first launch.
  if (splashAlreadyHidden)
    return;
  splashAlreadyHidden = TRUE;
  __block CGFloat shift;
  
  splashView.hidden = FALSE;

  [UIView animateWithDuration: .24
    delay: 2.0 
    options: 0
    animations: ^{
      CGPoint splashCenter;
      splashCenter = splashView.center;
      //Shift the splash view off-screen upwards (use += to shift it down, or adjust the x coord
      //to shift it to the side...
      shift = [UIApplication sharedApplication].keyWindow.bounds.size.height
      splashCenter.y -= shift;
      splashView.center = splashCenter;
    }
    completion: ^(BOOL finished) {
      splashView.hidden = TRUE;
      //Shift the splash view back into place in case we want to display it again.
      CGPoint splashCenter;
      splashCenter = splashView.center;
      splashCenter.y += shift;
      splashView.center = splashCenter;
    }
    ];
}
If you want to support iOS versions prior to 4.0, you can use a similar approach to the above using the UIView class methods beginAnimations:context: ... commitAnimations. In that case, though, you would need to set up a separate hideSplash method, and invoke it using performSelector:withObject:afterDelay so you delay sliding the splash-screen away.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 410
16 members and 394 guests
Atatator, chiataytuday, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, MAMN84, n00b, PowerGoofy, QuantumDoja, Retouchable, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0