在我的项目中有一个功能,当用户在顶部栏上滑动时,一个屏幕将出现上下动画
有两个视图控制器 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];
}
但是这不会从上到下给出动画
我想实现导航 推:=顶部 - 底部 Pop:= bottom - top
请帮帮我 谢谢
答案 0 :(得分:28)
您可以按如下方式将视图控制器从上到下推送:
的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];
}
使用以下代码从下到上弹出视图控制器:
- (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];
}
斯威夫特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)
}