Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreAnimation blinking animation stops after the view gets out of view and comes back. #240

Closed
migueldeicaza opened this issue Jun 28, 2022 · 2 comments

Comments

@migueldeicaza
Copy link
Owner

No description provided.

@JoeMatt
Copy link

JoeMatt commented Jun 30, 2022

More details on this?
Just looked at it on an my Mac the cursor was working. I did have to make my changes to fix the build first though.

This may work, adding isRemovedOnCompletion to false

    func updateCursorStyle (style: CursorStyle = .blinkBlock) {
        switch style {
        case .blinkUnderline, .blinkBlock, .blinkBar:
            let anim = CABasicAnimation.init(keyPath: #keyPath (CALayer.opacity))
            anim.duration = 0.7
            anim.autoreverses = true
            anim.repeatCount = Float.infinity
            anim.fromValue = NSNumber (floatLiteral: 1)
            anim.toValue = NSNumber (floatLiteral: 0.3)
            anim.isRemovedOnCompletion = false
            anim.timingFunction = CAMediaTimingFunction (name: .easeInEaseOut)
            sub.add(anim, forKey: #keyPath (CALayer.opacity))
        case .steadyBar, .steadyBlock, .steadyUnderline:
            sub.removeAllAnimations()
            sub.opacity = 1
        }

if that doesn't work, you need to recreate the anim on focus.

In my opinion, it should pause in the background anyway if it doesn't already. (looks to still blink when not focused for me).

@migueldeicaza
Copy link
Owner Author

Sorry, I should have written more about this.

CoreAnimation stops animations when the view is no longer presented (either you navigate away, or you go to the background on iOS). I implemented your suggestion to enable/disable the animation on focus (using the first responder hooks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants