开发者

Changing view from one xib to another xib with animation after some times

I have made a view based application which is load开发者_如何学运维ing a default view ...

My default view is a splash screen ..

What I want to achieve is once default view (splash view) finished loading, after few seconds it loads another view which is either a privacy policy or application screen.

Code in AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window.rootViewController = self.viewController;    
    [self.window makeKeyAndVisible];
    return YES;
}

No Change as usual ...

Above code load a view from splashscreen.xib file

Following code is in splashscreen.m

- (IBAction)loadPrivacyScreen {
    NSLog(@"Switching To Another View");
    PrivacyPolicyView *modal = [[PrivacyPolicyView alloc]initWithNibName:nil bundle:nil];
    modal.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:modal animated:YES];
    [modal release];
}


- (void)viewDidLoad {

    [super viewDidLoad];
    sleep(3);
    [self loadPrivacyScreen];
    // Do any additional setup after loading the view from its nib.
}

After three second it does get in to the loadPrivacyScreen funciton but doesn't load the view.

- (IBAction)loadPrivacyScreen;

I have created a method as IBAction because I want to hook that method with a button on privacy screen to check that function works ...

And surprisingly it works when you click the button. But it doest work on time.

Can anyone suggest me what am I doing wrong ?? or any other alternative to achieve same thing??

Note: I have also try changing

- (IBAction)loadPrivacyScreen;

to

- (void)loadPrivacyScreen;

But still same result. It is not switching ....


First of all iOS provides a simple way to load a splash screen. Just add a Image with 320x480 resolution in the name called default.png and add that to your project it will automatically use this image as splash screen image.

In your way call the loadPrivacy screen with a timer.

- (void)viewDidLoad {
   [super viewDidLoad];
   NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:3.00 target:self selector:@selector(loadPrivacyScreen) userInfo:nil repeats:NO];

}


- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window.rootViewController = self.viewController;    
    [self.window makeKeyAndVisible];
    [viewController showSplash];
}

And in the view controller, define a method like

> IBOutlet UIView *modelView;
- (void)showSplash;
- (void)hideSplash;
-(void)showSplash {
    UIViewController *modalViewController = [[UIViewController alloc] init];
    modalViewController.view = modelView;
    [self presentModalViewController:modalViewController animated:NO];
    [self performSelector:@selector(hideSplash) withObject:nil afterDelay:2.0];
}
//hide splash screen
- (void)hideSplash {
    [[self modalViewController] dismissModalViewControllerAnimated:YES];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜