总体目标:在 macOS 上使用自定义故事板 segue
手头的问题是响应者链。据苹果称:
此外,在 macOS 10.10 及更高版本中,视图控制器参与响应者链。NSViewController
如果我在 macOS 故事板中使用标准 segue,则目标视图控制器的行为符合预期——焦点、等效键、响应者链等。
但是,如果我使用自定义 segue,则目标视图控制器的行为不符合预期:( 具体来说,关键等效项神秘地无法工作 - 但是,在测试中,来自源视图控制器的按钮上的关键等效项继续工作(这不是t 有帮助/需要)
在 macOS 10.12 上,我正在使用以下自定义 segue……我做错了什么?
class PushSegue: NSStoryboardSegue {
override func perform() {
(sourceController as AnyObject).presentViewController(destinationController as! NSViewController, animator: PushAnimator())
}
}
class PushAnimator: NSObject, NSViewControllerPresentationAnimator {
func animatePresentation(of viewController: NSViewController, from fromViewController: NSViewController) {
viewController.view.wantsLayer = true
viewController.view.frame = CGRect(x: fromViewController.view.frame.size.width, y: 0,
width: fromViewController.view.frame.size.width, height: fromViewController.view.frame.size.height)
fromViewController.addChildViewController(viewController)
fromViewController.view.addSubview(viewController.view)
let futureFrame = CGRect(x: 0, y: 0, width: viewController.view.frame.size.width,
height: viewController.view.frame.size.height)
NSAnimationContext.runAnimationGroup({ context in
context.duration = 0.75
viewController.view.animator().frame = futureFrame
}, completionHandler:nil)
}
func animateDismissal(of viewController: NSViewController, from fromViewController: NSViewController) {
let futureFrame = CGRect(x: viewController.view.frame.size.width, y: 0,
width: viewController.view.frame.size.width, height: viewController.view.frame.size.height)
NSAnimationContext.runAnimationGroup({ context in
context.duration = 0.75
context.completionHandler = {
viewController.view.removeFromSuperview()
viewController.removeFromParentViewController()
}
viewController.view.animator().frame = futureFrame
}, completionHandler: nil)
}
}