小编典典

如何使用Swift在iOS中从右到左显示视图控制器

swift

我正在使用presentViewController呈现新屏幕

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

这将显示从下到上的新屏幕,但我希望不使用即可从右到左显示UINavigationController

我使用的是Xib而不是情节提要,该怎么办?


阅读 521

收藏
2020-07-07

共1个答案

小编典典

是否使用xibstoryboard正在使用都没有关系。通常,当您将视图控制器推入Presentor时,使用从右向左过渡UINavigiationController

更新

新增计时功能 kCAMediaTimingFunctionEaseInEaseOut

示例项目斯威夫特4
实现加入GitHub上

迅捷3和4.2

let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
view.window!.layer.add(transition, forKey: kCATransition)
present(dashboardWorkout, animated: false, completion: nil)

对象

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];

斯威夫特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)

在自定义转换的情况下,方法中的animated参数presentViewController似乎并不重要。它可以是任何值,true或者false

2020-07-07