YouTip LogoYouTip

Att Ios Ui View Transition

View switching is implemented through a series of animation effects, including curl transitions, flip transitions, card-style transitions, etc. ### Modify ViewController.xib as shown below ![Image 1: viewTransition](#) Create button actions in xib ### Modify ViewController.h ```objc #import @interface ViewController : UIViewController { UIView *view1; UIView *view2; } -(IBAction)flipFromLeft:(id)sender; -(IBAction)flipFromRight:(id)sender; -(IBAction)flipFromTop:(id)sender; -(IBAction)flipFromBottom:(id)sender; -(IBAction)curlUp:(id)sender; -(IBAction)curlDown:(id)sender; -(IBAction)dissolve:(id)sender; -(IBAction)noTransition:(id)sender; @end Declare two view instances in the ViewController class. The ViewController.h file code is as follows: ### Modify ViewController.m We will add a custom method setUpView to initialize the views. We will also create another method doTransitionWithType: to implement the transition from view1 to view2 and vice versa. Then we will execute the action method we created earlier, which is calling the doTransitionWithType: method with the transition type. ViewController.m code is as follows: ```objc #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { ; ; // Do any additional setup after loading the view, typically from a nib. } -(void)setUpView { view1 = [initWithFrame:self.view.frame]; view1.backgroundColor = ; view2 = [initWithFrame:self.view.frame]; view2.backgroundColor = ; [self.view addSubview:view1]; [self.view sendSubviewToBack:view1]; } -(void)doTransitionWithType:(UIViewAnimationTransition)animationTransitionType { if ([[self.view subviews] containsObject:view2 ]) { [UIView transitionFromView:view2 toView:view1 duration:2 options:animationTransitionType completion:^(BOOL finished){ ; }]; [self.view addSubview:view1]; [self.view sendSubviewToBack:view1]; } else{ [UIView transitionFromView:view1 toView:view2 duration:2 options:animationTransitionType completion:^(BOOL finished){ ; }]; [self.view addSubview:view2]; [self.view sendSubviewToBack:view2]; } } -(IBAction)flipFromLeft:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionFlipFromLeft]; } -(IBAction)flipFromRight:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionFlipFromRight]; } -(IBAction)flipFromTop:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionFlipFromTop]; } -(IBAction)flipFromBottom:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionFlipFromBottom]; } -(IBAction)curlUp:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionCurlUp]; } -(IBAction)curlDown:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionCurlDown]; } -(IBAction)dissolve:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionCrossDissolve]; } -(IBAction)noTransition:(id)sender { [self doTransitionWithType:UIViewAnimationOptionTransitionNone]; } - (void)didReceiveMemoryWarning { ; // Dispose of any resources that can be recreated. } @end ### Output Now when we run the application we will see the following output ![Image 2: viewTransitionOutput1](#) You can choose different buttons to see how the transition works. Choosing the curl transition will produce the effect as shown below ![Image 3: viewTransitionOutput2](#)
← Att Ios Ui PickerAtt Ios Ui Textview β†’