Skip to content

Instantly share code, notes, and snippets.

@SwCake1
Last active May 29, 2018 09:56
Show Gist options
  • Save SwCake1/be73e06038fac4d768bb0bbb2ac0f9b9 to your computer and use it in GitHub Desktop.
Save SwCake1/be73e06038fac4d768bb0bbb2ac0f9b9 to your computer and use it in GitHub Desktop.
ASDK animation example
override func animateLayoutTransition(_ context: ASContextTransitioning) {
if textNode.text == "" {
let finalTextFrame = context.finalFrame(for: textNode)
var finalButtonFrame = context.initialFrame(for: cancelButton)
finalButtonFrame.origin.x = UIScreen.main.bounds.width
UIView.animate(withDuration: 0.1, animations: {
self.textNode.frame = finalTextFrame
self.cancelButton.frame = finalButtonFrame
}, completion: { finished in
context.completeTransition(finished)
})
} else {
let finalTextFrame = context.finalFrame(for: textNode)
let finalButtonFrame = context.finalFrame(for: cancelButton)
cancelButton.frame = finalButtonFrame
let initialButtonFrame = context.initialFrame(for: cancelButton)
if initialButtonFrame.isEmpty {
cancelButton.frame.origin.x = UIScreen.main.bounds.width
}
UIView.animate(withDuration: 0.1, animations: {
self.textNode.frame = finalTextFrame
self.cancelButton.frame = finalButtonFrame
}, completion: { finished in
context.completeTransition(finished)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment