将 uiviewcontroller 推到另一个 viewcontroller 并使用从上到下的动画
push uiviewcontroller to another viewcontroller with animation from Top - bottom
在我的项目中有一个功能,当用户在顶部栏上滑动时,一个屏幕会出现从上到下的动画
有两个视图控制器
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];
}
但这并没有给出从上到下的动画
我想实现导航
推 := 顶部 - 底部
弹出:=底部 - 顶部
请帮帮我
谢谢
您可以像下面这样从上到下推送视图控制器:
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];
}
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)
}
在我的项目中有一个功能,当用户在顶部栏上滑动时,一个屏幕会出现从上到下的动画
有两个视图控制器 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];
}
但这并没有给出从上到下的动画
我想实现导航 推 := 顶部 - 底部 弹出:=底部 - 顶部
请帮帮我 谢谢
您可以像下面这样从上到下推送视图控制器:
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];
}
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)
}