【问题标题】:NSView distorted after NSWindow resizedNSWindow 调整大小后 NSView 扭曲
【发布时间】:2015-04-18 15:02:17
【问题描述】:

我正在使用animator() 在我的应用程序的框架(子视图)之间横向滚动NSScrollView。当动画发生并且我调整NSWindow 的大小时,整个NSView 会像这样扭曲:

这是负责转换的代码:

func goToFrame(frameNumber: Int) {
    dispatch_async(dispatch_get_main_queue(), {
        var clipView: NSClipView = self.container.contentView
        newOrigin: NSPoint = clipView.bounds.origin
        newOrigin.x = CGFloat(self.viewWidth * frameNumber)

        NSAnimationContext.beginGrouping()
        NSAnimationContext.currentContext().duration = 0.4
        self.container.contentView.animator().bounds.origin = newOrigin
        self.container.reflectScrolledClipView(self.container.contentView)
        NSAnimationContext.endGrouping()
    })
}

知道为什么会这样做吗?我在日志中没有收到任何警告。

【问题讨论】:

  • 不确定,但是:self.container.contentView.animator().bounds.origin = newOriginself.container.contentView.animator().setBoundsOrigin(newOrigin) 不同。由于bounds 是NSRect,所以你所做的就像var bounds = self.container.contentView.animator().bounds ; bounds.origin = newOrigin ; self.container.contentView.animator().bounds = bounds。设置整个边界矩形的动画可能与仅设置原点不同。此外,您在边界更改生效之前调用reflectScrolledClipView(_:),因为该更改正在被动画化。
  • 感谢 Ken,它的 .setBoundsOrigin() 就像一个魅力!

标签: macos swift nsview nswindow animator


【解决方案1】:

由 Ken Thomases 在评论中回答:

这一行:

self.container.contentView.animator().bounds.origin = newOrigin

应该改为:

self.container.contentView.animator().setBoundsOrigin(newOrigin)

【讨论】:

    猜你喜欢
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 2016-06-18
    • 2020-01-04
    • 1970-01-01
    相关资源
    最近更新 更多