简体   繁体   中英

switch between uivewconrollers with swipe gesture

I am trying to switch between 4 VC with swipe gesture (up) and little animation,I am using xib :

-(IBAction)gotonext:(UISwipeGestureRecognizer *)recognizer{
ibasar *ibas =[[ibasar alloc]initWithNibName:@"ibasar" bundle:nil];


[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

[self.view addSubview:ibas.view];

[UIView commitAnimations];

  }

the problem is that when I switch from first VC to the second the with done, but when I switch from the second to the third the app is stopped ! Despite using the same code for switch ! any help please ..thanks in advance

Firstly, use block animation if you are going to animate. Not the old animation methods.

Secondly, you are just adding a sub views on top of each other. This is probably heavy on the memory. Either remove and discard the old view at the end of the animation or better yet, use a UINavigation view controller that handles all that for you.

You could create a CATransition animation. Here's an example of how you can slide a second view (from left) into the screen while pushing the current view out:

UIView *theParentView = [self.view superview];

CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[theParentView addSubview:yourSecondViewController.view];
[self.view removeFromSuperview];

[[theParentView layer] addAnimation:animation forKey:@"MainView"];

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