如何使用Swift在iOS中从右到左呈现视图控制器 [英] How to present view controller from right to left in iOS using Swift

查看:697
本文介绍了如何使用Swift在iOS中从右到左呈现视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用presentViewController来呈现新屏幕

I am using presentViewController to present new screen

let dashboardWorkout = DashboardWorkoutViewController()
presentViewController(dashboardWorkout, animated: true, completion: nil)

这会从下到上显示新屏幕,但我想要它呈现从右到左不使用 UINavigationController

This presents new screen from bottom to top but I want it to presented from right to left without using UINavigationController.

我使用的是Xib而不是故事板,所以我该怎么做?

I am using Xib instead of storyboard so how can I do that ?

推荐答案

如果您使用的是 xib storyboard ,则无关紧要。通常,当您将视图控制器推送到presentor的 UINavigiationController 时,会使用从右到左的过渡。

It doesn't matter if it is xib or storyboard that you are using. Normally, the right to left transition is used when you push a view controller into presentor's UINavigiationController.

更新

添加计时功能 kCAMediaTimingFunctionEaseInEaseOut

示例项目,其中添加了 Swift 4 实施GitHub

Sample project with Swift 4 implementation added to GitHub



Swift 3& 4

let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut)
view.window!.layer.add(transition, forKey: kCATransition)
present(dashboardWorkout, animated: false, completion: nil)



ObjC

CATransition *transition = [[CATransition alloc] init];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:dashboardWorkout animated:false completion:nil];



Swift 2.x

let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut)
view.window!.layer.addAnimation(transition, forKey: kCATransition)
presentViewController(dashboardWorkout, animated: false, completion: nil)

好像是动画参数在这个自定义转换的情况下, presentViewController 方法并不重要。它可以是任何值, true false

Seems like the animated parameter in the presentViewController method doesn't really matter in this case of custom transition. It can be of any value, either true or false.

这篇关于如何使用Swift在iOS中从右到左呈现视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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