你如何从屏幕顶部而不是底部呈现 UIViewController? [英] How do you present a UIViewController from the top of the screen instead of the bottom?

查看:17
本文介绍了你如何从屏幕顶部而不是底部呈现 UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIViewController 并且我使用 presentModalViewController:controllerr animation:YES 来呈现它,但我希望它从屏幕顶部向下滑动而不是从底部向上滑动,有什么方法可以做到这一点?

I am using a UIViewController and I use presentModalViewController:controllerr animated:YES to present it but I would like if it would slide down from the top of the screen instead of up from the bottom, any way to do this?

推荐答案

我创建了一个函数,用于从所有 4 个方向推送 ViewControllers:

I created a function for pushing the ViewControllers from all 4 directions:

- (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

这篇关于你如何从屏幕顶部而不是底部呈现 UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆