Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 没有用于在UISplitViewController中显示和隐藏主UIViewController的动画,用于后续演示(primaryEdge=.training)_Ios_Swift - Fatal编程技术网

Ios 没有用于在UISplitViewController中显示和隐藏主UIViewController的动画,用于后续演示(primaryEdge=.training)

Ios 没有用于在UISplitViewController中显示和隐藏主UIViewController的动画,用于后续演示(primaryEdge=.training),ios,swift,Ios,Swift,因此,我在AppDelegate中使用了具有以下配置的UISplitViewController: func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds)

因此,我在AppDelegate中使用了具有以下配置的UISplitViewController:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    window = UIWindow(frame: UIScreen.main.bounds)
    let splitVC = UISplitViewController()
    let masterVC = UIViewController()
    let detailVC = UIViewController()
    splitVC.viewControllers = [masterVC, detailVC]
    splitVC.preferredDisplayMode = .primaryHidden
    splitVC.primaryEdge = .trailing
    window!.backgroundColor = .white
    window!.rootViewController = splitVC
    window!.makeKeyAndVisible()
    return true
}
由于我使用的主VCs和详细VCs没有导航控制器,因此我在UISplitViewController扩展中编写了一些用于切换(显示/隐藏)主VCs的函数:

extension UISplitViewController {
func showMasterView(from edge: PrimaryEdge = .leading,  completion: (()->Void)? = nil) {
    primaryEdge = edge
    UIView.animate(withDuration: 0.5, animations: {
        self.preferredDisplayMode = .allVisible
    }) { (animationFinished) in
        if let completion = completion, animationFinished {
            completion()
        }
    }
}

func hideMasterView(completion: (()->Void)? = nil) {
    UIView.animate(withDuration: 0.5, animations: {
        self.preferredDisplayMode = .primaryHidden
    }) { (animationFinished) in
        if let completion = completion, animationFinished {
            completion()
        }
    }
}


func toggleMasterView( completion: (()->Void)? = nil) {
    var nextDisplayMode: UISplitViewController.DisplayMode
    switch(self.preferredDisplayMode) {
    case .primaryHidden:
        nextDisplayMode = .allVisible
    default:
        nextDisplayMode = .primaryHidden
    }
    UIView.animate(withDuration: 0.5, animations: {
        self.preferredDisplayMode = nextDisplayMode
    }) { (animationFinished) in
        if let completion = completion, animationFinished {
            completion()
        }
    }
}

func toggleMasterViewNew() {
   let barButtonItem = self.displayModeButtonItem
   UIApplication.shared.sendAction(barButtonItem.action!, to: barButtonItem.target, from: nil, for: nil)
}
}
当splitVC.primaryEdge=.leading(默认情况下)时,这些函数对动画非常有用,但不适用于.Training-动画出现故障时,主vc仅用于显示和隐藏。 我知道我可以编写自定义解决方案,但我想知道,为什么。拖尾演示破坏了切换动画

所以,我希望我们能一起找到答案:)