Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created May 21, 2021 08:10
Show Gist options
  • Save fredriccliver/9204b6d9d229258a6e8e30a336b69a66 to your computer and use it in GitHub Desktop.
Save fredriccliver/9204b6d9d229258a6e8e30a336b69a66 to your computer and use it in GitHub Desktop.
func commentButtonSlideIn(fromRight:Bool = true){
if(fromRight){
myButton.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: 15).isActive = true
myButton.frame.origin.x = UIScreen.main.bounds.width
}else{
myButton.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor, constant: -15).isActive = true
myButton.frame.origin.x = -80
}
var destX = UIScreen.main.bounds.width - (80 - 15)
if(!fromRight){
destX = -15
}
let layer = myButton.layer
UIViewPropertyAnimator(duration: 0.5, curve: .easeIn, animations: {
layer.frame.origin.x = destX
}).startAnimation()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment