gpt4 book ai didi

ios - 我怎样才能让这个过程向相反的方向发展呢?

转载 作者:行者123 更新时间:2023-11-30 12:42:47 25 4
gpt4 key购买 nike

我有一段从左到右的代码,但我希望它从右到左。我该怎么做呢?

let screenWidth = (UIScreen.mainScreen().bounds).width
let screenHeight = (UIScreen.mainScreen().bounds).height

let firstVCView = sourceViewController.view
let secondVCView = destinationViewController.view
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)

// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)

// Animate the transition.
UIView.animateWithDuration(0.3, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)

}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController ,
animated: false,
completion: nil)
}

最佳答案

您需要做的是将第二个 View 最初放置在第一个 View 的左侧而不是右侧。

secondVCView.frame = CGRectMake(-screenWidth, 0.0, screenWidth, screenHeight)

然后在你想要反转的动画中:

firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)

最终结果:

let screenWidth = (UIScreen.mainScreen().bounds).width
let screenHeight = (UIScreen.mainScreen().bounds).height

let firstVCView = sourceViewController.view
let secondVCView = destinationViewController.view
secondVCView.frame = CGRectMake(-screenWidth, 0.0, screenWidth, screenHeight)

// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)

// Animate the transition.
UIView.animateWithDuration(0.3, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, screenWidth, 0.0)

}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController ,
animated: false,
completion: nil)
}

关于ios - 我怎样才能让这个过程向相反的方向发展呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42037313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com