Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
UIViewPropertyAnimator completion called when paused

I haven’t used UIViewPropertyAnimator very much (still an old fashioned blocks guy) and I’m seeing some behavior that I can’t explain and that the docs don’t really provide any insight on.

Why does an animator’s completion block get called with a finalPosition of .end even when the animator is paused immediately after it’s started?

let view = UIView()
let animator = UIViewPropertyAnimator(duration: 4, curve: .linear, animations: {
    view.alpha = 0
})

animator.addCompletion { position in
    print("done")
    switch position {
    case .start: print("start")
    case .current: print("current")
    case .end: print("end")
    }
}

animator.startAnimation()
print("starting")
animator.pauseAnimation()
print("pausing")

Output:

starting
pausing
done
end
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The problem, as @matt alluded to, is that your view isn't in a visible UIWindow, so the animations complete immediately. You get the same output if you comment out the animator.pauseAnimation() statement.

You can fix this if you're using a playground by making view the liveView of the playground page:

import PlaygroundSupport
import UIKit

let view = UIView()
PlaygroundPage.current.liveView = view

// etc.
over 4 years ago · Santiago Trujillo Relatório

0

If you read the documentation of addCompletion from Apple's developer site, one of the parameter is the finalPosition. And you can use the value to determine whether the animation stopped at the beginning, end, or somewhere in the middle. And calling pauseAnimation will trigger that completion block with a somewhere in the middle position.

Parameters completion A block to execute when the animations finish. This block has no return value and takes the following parameter:

finalPosition The ending position of the animations. Use this value to determine whether the animations stopped at the beginning, end, or somewhere in the middle.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda