全画面で遷移したいとき、下から出したくないとき、ありますよね。
以下はUIButtonにaddTargetし、遷移する関数です。
@objc func buttonTapped() {
let nextVC = nextViewController()
nextVC.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
nextVC.modalPresentationStyle = UIModalPresentationStyle.fullScreen
self.navigationController?.pushViewController(nextVC, animated: true)
}
UIModalTransitionStyleは列挙型で、は遷移アニメーションを指定することができます。
public enum UIModalTransitionStyle : Int {
case coverVertical = 0
case flipHorizontal = 1
case crossDissolve = 2
@available(iOS 3.2, *)
case partialCurl = 3
}
デフォルトではcoverVerticalが設定されているので、自然に遷移する(?)crossDissolveに変えます。
同様にmodalPresentationStyleも列挙型の中からfullScreenに変更します。
ちなみにmodalPresentationStyleは以下のように書かれています。
public enum UIModalPresentationStyle : Int {
case fullScreen = 0
@available(iOS 3.2, *)
case pageSheet = 1
@available(iOS 3.2, *)
case formSheet = 2
@available(iOS 3.2, *)
case currentContext = 3
@available(iOS 7.0, *)
case custom = 4
@available(iOS 8.0, *)
case overFullScreen = 5
@available(iOS 8.0, *)
case overCurrentContext = 6
@available(iOS 8.0, *)
case popover = 7
@available(iOS 7.0, *)
case none = -1
@available(iOS 13.0, *)
case automatic = -2
}