objective-c - Animate 替换 UISplitViewController 中的详细信息 View

标签 objective-c uisplitviewcontroller transition

我有一个 Storyboard设置,在某些时候,一个按钮会用另一个按钮替换详细 View 。默认情况下,根本没有任何转换: View Controller 突然被替换。我可以创建一个吗?如何创建?

我的猜测是使用自定义转换 - 就像您通常为 View 更改使用自定义动画一样 - 但我不知道如何实现 Split View Controller 的“替换”行为。

最佳答案

我使用自定义segue 做到了这一点,当有 splitViewController 时,我会“显示详细信息”,否则我会尝试推送/呈现模式。全部动画化。显示模态动画将通过变换淡出旧 Controller 并通过变换更改显示新 Controller

class ShowDetailSegue: UIStoryboardSegue {

    private let showFromScale : CGFloat = 0.8
    private let hideToScale : CGFloat = 1.2
    private let animationDuration : NSTimeInterval = 0.33

    override func perform() {

        let sourceVC = self.sourceViewController as! UIViewController
        let destinationVC = self.destinationViewController as! UIViewController
        let animated = true

        if let splitVC = sourceVC.splitViewController where splitVC.isInSplitView {
            // splitview with detail is visible, we will show detail with animation
            showDetail(splitVC, sourceVC : sourceVC, destinationVC: destinationVC, animated: animated)
        } else if let navController = sourceVC.navigationController {
            // there is no split view – just push to navigation controller
            sourceVC.navigationController?.pushViewController(destinationVC, animated: animated)
        } else {
            // no navigation found, let just present modal
            sourceVC.presentViewController(destinationVC, animated: animated, completion: nil)
        }

    }

    private func showDetail(splitVC : UISplitViewController, sourceVC : UIViewController, destinationVC : UIViewController, animated : Bool) {

        let newDetailVC = GeneralNavigationController(rootViewController: destinationVC)
        newDetailVC.applyAppearance()

        if !animated {

            splitVC.showDetailViewController(newDetailVC, sender: sourceVC)

        } else {

            var currentDetailVC = splitVC.viewControllers.last as! UIViewController

            if let currentDetailNC = currentDetailVC as? UINavigationController {
                currentDetailVC = currentDetailNC.topViewController
            }

            UIView.animateWithDuration(animationDuration / 2.0, animations: { () -> Void in
                // hide the old view with transform

                currentDetailVC.view.alpha = 0
                currentDetailVC.view.transform = CGAffineTransformMakeScale(self.hideToScale, self.hideToScale)
                currentDetailVC.navigationController?.navigationBar.alpha = 0

                }, completion: { (completed) -> Void in

                    newDetailVC.navigationController?.navigationBar.alpha = 0
                    newDetailVC.view.alpha = 0
                    newDetailVC.view.transform = CGAffineTransformScale(newDetailVC.view.transform, self.showFromScale, self.showFromScale)

                    splitVC.showDetailViewController(newDetailVC, sender: sourceVC)

                    // Show new view

                    UIView.animateWithDuration(self.animationDuration / 2.0, animations: { () -> Void in

                        newDetailVC.view.alpha = 1
                        newDetailVC.view.transform = CGAffineTransformScale(newDetailVC.view.transform, 1 / self.showFromScale, 1 / self.showFromScale)

                        newDetailVC.navigationController?.navigationBar.alpha = 1

                        }, completion: { (completed) -> Void in

                            currentDetailVC.view.transform = CGAffineTransformScale(currentDetailVC.view.transform, 1 / self.hideToScale, 1 / self.hideToScale)
                    })
            })


        }


    }

}

关于objective-c - Animate 替换 UISplitViewController 中的详细信息 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28573900/

相关文章:

objective-c - 如何检查字符串是否与 objective-c 中的正则表达式匹配?

objective-c - 将 DTCoreText 与 xcode 项目集成

iOS:UILabel 在 View 中居中

ios - dismissview Controller 在 splitView 或 tabBar Controller 中不起作用

javascript - Css Transition 不响应

ios - IAP 自动更新沙盒帐户 - 无法连接到 iTunes Store 错误

ios - 如何对齐 SKPhysicsBody 和 SKShapeNode?

ios - 在 Master 上点击新项目时从 Detail viewController 中关闭模态

使用步骤对 png 序列进行 CSS 转换

r - 来自不同患者就诊序列的马尔可夫转移矩阵