あなたはこのコードを試すことができます:
import UIKit
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// Method used to detect when a tab bar button has been tapped
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
// Creating the 'to' and 'from' views for the transition
let fromView = tabBarController.selectedViewController!.view
let toView = viewController.view
if fromView == toView {
// If views are the same, then don't do a transition
return false
}
self.view.userInteractionEnabled = false
UIView.transitionFromView(fromView, toView: toView, duration: 2.0, options: .TransitionCrossDissolve, completion: nil)
self.view.userInteractionEnabled = true
return true
}
}
そして、ここでは、問題は次のようになります
import UIKit
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// Method used to detect when a tab bar button has been tapped
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
// Creating the 'to' and 'from' views for the transition
let fromView = tabBarController.selectedViewController!.view
let toView = viewController.view
if fromView == toView {
// If views are the same, then don't do a transition
return false
}
self.view.userInteractionEnabled = false
if let window = fromView.window {
let overlayView = UIScreen.mainScreen().snapshotViewAfterScreenUpdates(false)
viewController.view.addSubview(overlayView)
UIView.transitionFromView(fromView, toView: toView, duration: 2.0, options: .TransitionCrossDissolve, completion: { (finish) in
window.rootViewController = viewController
UIView.animateWithDuration(0.4, delay: 0.0, options: .TransitionCrossDissolve, animations: {
overlayView.alpha = 0
}, completion: { (finish) in
overlayView.removeFromSuperview()
})
})
}
self.view.userInteractionEnabled = true
return true
}
}