简体   繁体   中英

NSView distorted after NSWindow resized

I'm using the animator() to scroll a NSScrollView sideways between frames (child views) of my app. When the animation is happening and I resize the NSWindow the whole NSView gets distorted like so:

NSView在调整NSWindow的大小时会变形

Here's the code responsible for the transition:

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()
    })
}

Any idea why it would do that? I don't get any warnings in the log.

Answered by Ken Thomases in a comment:

This line:

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

should be changed to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM