gpt4 book ai didi

ios - 如何延迟或减慢 View Controller 之间的转换?

转载 作者:搜寻专家 更新时间:2023-11-01 07:28:24 26 4
gpt4 key购买 nike

所以我在屏幕上有一个按钮,它通过 Storyboard与插入赛格威相​​连。我按下按钮,它会转到下一个 View Controller 。

如果我想将过渡速度放慢 1-2 秒,我该怎么做?

最佳答案

您可以在延迟后使用 performSegueWithIdentifier 方法的第一个 View Controller 中创建一个方法。

然后将 View Controller 上的按钮连接到该方法。

代码示例:

Storyboard

这里我有一个初始 View Controller ,带有一个到第二个 View Controller 的手动 segue。

enter image description here

我已使用以下代码将 Fire Method 按钮连接到初始 View Controller 上的 IBAction:

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// This method is connected to the Fire Method button
@IBAction func fireMethodBttnTouched(sender: AnyObject) {

let delay = 1 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) { () -> Void in

self.performSegueWithIdentifier("showSecondViewController", sender: self)
}
}

}

您可以根据需要调整延迟常数。

关于ios - 如何延迟或减慢 View Controller 之间的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34366678/

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