我正在使用 UIViewController 并且我使用 presentModalViewController:controllerr animated:YES 来呈现它,但我想它是否会从屏幕顶部向下滑动而不是从底部向上滑动,有什么办法吗?
问问题
8340 次
5 回答
7
我创建了一个ViewControllers
从所有 4 个方向推送的函数:
- (void) slideLayerInDirection:(NSString *)direction andPush:(UIViewController *)dstVC {
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = direction;
[self.view.layer addAnimation:transition forKey:kCATransition];
[self pushViewController:dstVC animated:NO];
}
头文件包含以下内容:
#import <QuartzCore/QuartzCore.h>
#define direction_left kCATransitionFromLeft
#define direction_top kCATransitionFromBottom
#define direction_right kCATransitionFromRight
#define direction_bottom kCATransitionFromTop
于 2013-02-06T15:29:30.767 回答
5
public extension UINavigationController {
func pushViewControllerFromTop(viewController vc: UIViewController) {
vc.view.alpha = 0
self.present(vc, animated: false) { () -> Void in
vc.view.frame = CGRect(x: 0, y: -vc.view.frame.height, width: vc.view.frame.width, height: vc.view.frame.height)
vc.view.alpha = 1
UIView.animate(withDuration: 1,
animations: { () -> Void in
vc.view.frame = CGRect(x: 0, y: 0, width: vc.view.frame.width, height: vc.view.frame.height)
},
completion: nil)
}
}
func dismissViewControllerToTop() {
if let vc = self.presentedViewController {
UIView.animate(withDuration: 1,
animations: { () -> Void in
vc.view.frame = CGRect(x: 0, y: -vc.view.frame.height, width: vc.view.frame.width, height: vc.view.frame.height)
},
completion: { complete -> Void in
if complete {
self.dismiss(animated: false, completion: nil)
}
})
}
}
}
于 2016-03-09T02:19:40.180 回答
3
我使用以下代码从顶部为 viewController 设置动画。
[self.mainViewController.view addSubview:modalViewController.view];
modalViewController.view.frame = CGRectMake(modalViewController.view.frame.origin.x,
-modalViewController.view.frame.size.height,
modalViewController.view.frame.size.width,
modalViewController.view.frame.size.height);
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^(void){
modalViewController.view.frame = CGRectMake(modalViewController.view.frame.origin.x,
0,
modalViewController.view.frame.size.width,
modalViewController.view.frame.size.height);
} completion:^(BOOL finished){
[modalViewController.view removeFromSuperview];
[self.mainViewController presentViewController:modalViewController animated:NO completion:nil];
}];
它将 的 添加到中UIView
,对其进行动画处理,然后从 中删除并且没有动画。modalViewController
mainViewController
UIView
mainViewController
presentsViewController:
于 2014-03-25T10:13:20.050 回答
0
您所描述的不是内置的过渡样式;有关 Apple 提供的列表,请参见此处。如果你绝对需要你的视图控制器以这种方式出现,你必须自己制作动画。
于 2011-08-31T23:44:10.240 回答
0
您必须#import
在QuartzCore
框架中添加过渡动画,然后更改:
animated:YES
至:
animated:NO
。
于 2013-02-06T15:33:53.283 回答