我對 swift 和 xcode 非常陌生。我最近一直在嘗試創建一個有趣的應用程式...
我想要實作的目標:(應用程式啟動標志影片,在應用程式加載后它將帶你到主頁故事板)。我最近看了
我的家庭設定(我希望它加載的內容)通知我確實更改了類:

啟動/視圖控制器代碼:
import UIKit
class ViewController: UIViewController {
private lazy var imageView: UIImageView = {
lazy var imageView = UIImageView(frame: CGRect(x: 0, y: 0,width:150,height:150))
imageView.image = UIImage(named: "RobloxStudio")
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(imageView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
imageView.center = view.center
DispatchQueue.main.asyncAfter(deadline: .now() 0.5, execute: {
self.animate()
})
}
private func animate(){
UIView.animate(withDuration: 1, animations: {
let size = self.view.frame.size.width * 2
let diffX = size - self.view.frame.size.width
let diffY = self.view.frame.size.height - size
self.imageView.frame = CGRect(
x: -(diffX/2),
y: diffY/2,
width: size,
height: size
)
})
UIView.animate(withDuration: 1.5, animations: {
self.imageView.alpha = 0
}, completion: { done in
if done{
DispatchQueue.main.asyncAfter(deadline: .now() 0.5, execute: {
let viewController = HomeViewController()
viewController.modalTransitionStyle = .crossDissolve
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
})
}
})
}
}
HomeViewController 的代碼:
import UIKit
class HomeViewController: UIViewController{
override func viewDidLoad(){
super.viewDidLoad()
}
}
有沒有更簡單的方法來制作啟動影片,并將其加載到我已經擁有設計的故事板上?有小費嗎?
uj5u.com熱心網友回復:
您首先需要在情節提要中添加情節提要 ID HomeViewController,按照慣例,您通常使用視圖控制器的名稱,因此您的情節提要 ID 為"HomeViewController"
因此,在以紅色突出顯示的框中,輸入文本"HomeViewController":

完成后,您需要實體化它。您將從中更改以下代碼ViewController:
DispatchQueue.main.asyncAfter(deadline: .now() 0.5, execute: {
let viewController = HomeViewController()
viewController.modalTransitionStyle = .crossDissolve
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
})
對此:
DispatchQueue.main.asyncAfter(deadline: .now() 0.5, execute: {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
viewController.modalTransitionStyle = .crossDissolve
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
})
在這段代碼中,我們首先找到被UIStoryboard呼叫的"Main"
let storyboard = UIStoryboard(name: "Main", bundle: nil)
然后我們尋找與identifier我們在情節提要中設定的情節提要相同的情節提要,在這種情況下"HomeViewController"
let viewController = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
于是最后我們設定modalTransitionStyle和modalPresentationStyle對的viewController,我們提出之前。
viewController.modalTransitionStyle = .crossDissolve
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/405682.html
標籤:
上一篇:Swiftui影片日歷日期
