Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push uiviewcontroller to another viewcontroller with animation from Top - bottom

In my project there is feature when user swipe on top bar one screen will appear with top to bottom animation

There are two view controller oneviewcontroller.m

- (void)swipe
{
    listViewController *list_obj=[[listViewController alloc] initWithNibName:@"listViewController" bundle:NULL];
    UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
    [UIView beginAnimations: nil context: nil];
    [UIView setAnimationTransition: trans forView: [self.view window] cache: YES];
    [self.navigationController pushViewController:list_obj animated:YES];
    [UIView commitAnimations];
}

But this does not give the animation from top-bottom

I want to implement the navigation from Push := top - bottom Pop : = bottom - top

please help me Thank you

like image 872
iOS developer Avatar asked Apr 14 '16 10:04

iOS developer


1 Answers

You can push a view controller top to bottom like follows:

Obj-C:

- (void) pushVC:(UIViewController )dstVC {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:dstVC animated:NO];
}

Use the below code to pop view controller from Bottom to Top:

- (void) popVC {
    CATransition *transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromBottom;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController popViewControllerAnimated:NO];
}

Swift 3:

  func open() {
    let settingsVC = SettingsVC()
    let transition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromTop
    navigationController?.view.layer.add(transition, forKey: kCATransition)
    navigationController?.pushViewController(settingsVC, animated: false)
  }

  func close() {
    let transition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionFade
    transition.subtype = kCATransitionFromBottom
    navigationController?.view.layer.add(transition, forKey:kCATransition)
    let _ = navigationController?.popViewController(animated: false)
  }
like image 125
Dinesh Avatar answered Sep 21 '22 12:09

Dinesh