JNWAnimatableWindow icon indicating copy to clipboard operation
JNWAnimatableWindow copied to clipboard

Is JNWAnimatableWindow interruptible?

Open eonist opened this issue 8 years ago • 11 comments

I just found NSAnimatablePropertyContainer. Then I found your lib on github.

eonist avatar Mar 16 '17 14:03 eonist

What do you mean by interruptible? Do you mean where it interpolates between the current animation state and a new state?

jwilling avatar Mar 16 '17 15:03 jwilling

Like how UIPropoertyAnimator is interruptible. Like you can make animation that is interactive. I'm working on this: https://vimeo.com/208548367

eonist avatar Mar 16 '17 16:03 eonist

Sorry for the delay. The implementation is not very complex, so if you're curious I'd just take a look. The frame resizing animation uses an explicit animation without taking the presentation layer's bounds into account, so it will not interpolate as you're suggesting. That being said, the purpose of this library is to provide access to a layer, which can be animated as you please. It's easily accomplished with the provided by the -layer property.

jwilling avatar Mar 21 '17 01:03 jwilling

Thx for your reply. Your project came up while I researched NSAnimatablePropertyContainer. I guess its not like the new UIViewPropertyAnimator available since iOS 10. Which is all about being interruptible.

eonist avatar Mar 21 '17 12:03 eonist

It's not hard to accomplish the same effect by setting the layer's speed to 0.

-- Jonathan

On Mar 21, 2017, at 5:40 AM, Eon [email protected] wrote:

Thx for your reply. Your project came up while I researched NSAnimatablePropertyContainer. I guess its not like the new UIViewPropertyAnimator available since iOS 10. Which is all about being interruptible.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwilling/JNWAnimatableWindow/issues/10#issuecomment-288066218, or mute the thread https://github.com/notifications/unsubscribe-auth/AA08m13QUoUrAgAK-A1G0zvjZz28Z_Xjks5rn8VBgaJpZM4MfaZG .

jwilling avatar Mar 21 '17 14:03 jwilling

Im using Display link. Just found one of your blog posts that helped make it more performant: http://jwilling.com/blog/osx-animations/ Thanks! When are you transitioning to swift? ^^

eonist avatar May 07 '17 14:05 eonist

👆 BTW your theory in this blog post is on point. Animating .frame.origin is laggy. Animating with .layer.position is smooth. Very noticeable when the amount of NSViews are numerous.

eonist avatar May 09 '17 09:05 eonist

I'm still having huge problems getting hitTest to work with .layer.position animation. I think I will have to write a recursive method that traverse up the hierarchy to find the localGlobal and globalLocal position to hit test with.

eonist avatar May 09 '17 09:05 eonist

Worked! Sharing is caring: This code takes care of converting between local and global coordinates when animating with layer instead of frame:

   /**
     * New
     * NOTE: convert(p,nil) usualy converts flipped geometry, but when using layer.position it wont work
     */
    func flipY(_ p:CGPoint)->CGPoint{
        return CGPoint(p.x, WinParser.height(window!) - p.y)/*flips the window y coordinates*/
    }
    /**
     * New
     * Converts global p to local p
     */
    func globToLoc(_ p:CGPoint)->CGPoint{
        let flippedPoint = flipY(p)
        let offset = globalPos()
        let localPoint = flippedPoint - offset
        return localPoint
    }
    /**
     * New
     * Returns the globalPoint of the self.frame.origin (where is this view in the POV of 0,0 of the upper most view)
     */
    func globalPos()->CGPoint{
        var offset:CGPoint = CGPoint()
        var parent:NSView? = self.superview
        while parent?.superview != nil {
            offset += parent!.layer!.position
            parent = parent?.superview
        }
        return offset
    }

eonist avatar May 09 '17 10:05 eonist

The WinParser:

/**
     * NOTE: returns the window height (including the titleBar height)
     * NOTE: to return window height not including the titleBar height, the use window!.frame.height
     * NOTE: this method can also be used if you diff this method and the frame.height to get the titlebar height
     * NOTE: to get the width of a window yu can use: window!.frame.width
     */
    static func height(_ window:NSWindow)->CGFloat{
        return NSWindow.contentRect(forFrameRect: window.frame, styleMask: window.styleMask).height
    }

eonist avatar May 09 '17 10:05 eonist

Nice, thanks for sharing that!

jwilling avatar May 24 '17 06:05 jwilling