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

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

问题描述

我正在使用UIViewController并且我使用presentModalViewController:controllerr animated: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 的函数: / p>

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天全站免登陆