简体   繁体   中英

View Transitioning

I'm new to Objective-C programming and I'm having a little trouble understanding how I transition between two views.

Basically, I have my main view (the view that loads up when the application opens) and I want to transition to a new view on pressing a button. The user will not need to go back to the main view after pressing the button -- it's basically a title screen.

Could someone please briefly explain the steps I would need to take to make this happen?

Thanks a lot.

You could make use of UIView's class method transitionFromView:toView:duration:options:completion: . A call to switch from viewA to viewB could look like this:

[UIView transitionFromView:viewA 
                    toView:viewB 
                  duration:1.0 
                   options:UIViewAnimationOptionTransitionFlipFromLeft 
                completion:^(BOOL finished){
                    [viewA release];
                }];

As you mentioned the user won't get back to the mainView I added something to the completion parameter to get rid of viewA afterwards.

You can find the animation options in the constants of the UIView class documentation.

If you don't just want to copy & paste the code you should follow Apple's sample code step by step and remember you can download it:

ViewTransitions sample application

The ViewTransitions sample application demonstrates how to perform transitions between two views using built-in Core Animation transitions. By looking at the code, you'll see how to use a CATransition object to set up and control transitions.

If it's going to be a modal view, you can push on a new modal view controller which will then later be popped off when work is complete. These are usually intended for small amounts of work

[container presentModalViewController:yourNavigationViewController animated:YES];

Otherwise you can modify the UIView stack using the two UIView transition class methods:

+ transitionWithView:duration:options:animations:completion:
+ transitionFromView:toView:duration:options:completion:

For more info on these check out Apple's UIView class docs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM