Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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
Objective c 如何在NSViewController.transition期间将NSViewController固定到NSPover顶部?_Objective C_Swift_Macos_Cocoa_Appkit - Fatal编程技术网

Objective c 如何在NSViewController.transition期间将NSViewController固定到NSPover顶部?

Objective c 如何在NSViewController.transition期间将NSViewController固定到NSPover顶部?,objective-c,swift,macos,cocoa,appkit,Objective C,Swift,Macos,Cocoa,Appkit,我一直在尝试在nspover中创建从一个子视图控制器到另一个子视图控制器的滑动转换 我的问题是,在转换过程中,子视图控制器不会固定在NSPopover的顶部。它们从底部或顶部设置动画: 预期行为:两个子视图控制器在转换期间应保持在顶部,并且应简单地水平滑动 这是我编写的用于触发转换的函数: func loadViewController(\uchildviewcontroller:NSViewController,带转换转换选项:NSViewController.transitionOptio

我一直在尝试在nspover中创建从一个子视图控制器到另一个子视图控制器的滑动转换

我的问题是,在转换过程中,子视图控制器不会固定在NSPopover的顶部。它们从底部或顶部设置动画:

预期行为:两个子视图控制器在转换期间应保持在顶部,并且应简单地水平滑动

这是我编写的用于触发转换的函数:

func loadViewController(\uchildviewcontroller:NSViewController,带转换转换选项:NSViewController.transitionOptions?){
addChild(childViewController)
view.addSubview(childViewController.view)
childViewController.view.layer?.borderColor=NSColor(校准颜色:0,绿色:255,蓝色:0,alpha:1).cgColor
childViewController.view.layer?.borderWidth=2
childViewController.view.topAnchor.constraint(equalTo:view.topAnchor).isActive=true
view.layout()
让oldViewController=currentViewController
currentViewController=childViewController
oldViewController?.view.layer?.borderColor=NSColor(校准颜色:255,绿色:0,蓝色:0,alpha:1)。cgColor
oldViewController?.view.layer?.borderWidth=2
如果让oldViewController=oldViewController{
转换(从:oldViewController,到:currentViewController!,选项:transitionOptions???.slideLeft,completionHandler:{[weak oldViewController]中
oldViewController?.removeFromParent()
oldViewController?.view.removeFromSuperview()
})
}
NSAnimationContext.runAnimationGroup({(context)->中的Void
context.duration=0.5
context.allowsImplicationImation=true
self.parentPopover?.contentSize=NSSize(宽度:childViewController.preferredContentSize.width,高度:childViewController.preferredContentSize.height)
})
}
知道是什么导致了这个问题吗?我尝试过处理子视图控制器和父视图控制器的约束以及它们的帧大小。我只是不知道我做错了什么

我在这里上传了完整的可复制示例:


非常感谢你的帮助

如果您希望看到下面的动画

然后只需从动画块中删除内容大小的更新,如下所示

self.parentPopover?.contentSize=NSSize(宽度:childViewController.preferredContentSize.width,高度:childViewController.preferredContentSize.height)
NSAnimationContext.runAnimationGroup({(context)->中的Void
context.duration=0.5
context.allowsImplicationImation=true
}) {
oldViewController?.removeFromParent()
oldViewController?.view.removeFromSuperview()
}
更新:使popover内容保持动画效果(无需进行上述更改)

对于这种情况,您只需要翻转popover内容视图(MasterViewController视图)的坐标系


是的,但是我想让府绸的尺寸平滑地动画…非常感谢@Asperi!这真的很有效。:)
class PopoverContentView: NSView {
    override var isFlipped: Bool { true }
}

class MasterViewController: NSViewController {
    ...
    override func loadView() {
        self.view = PopoverContentView()
    }