This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let bigSquare = UIView(frame: CGRect(x: 0, y: 0, width: 120, height: 120)) | |
bigSquare.backgroundColor = UIColor.green | |
let smallSquare = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) | |
bigSquare.addSubview(smallSquare) | |
smallSquare.backgroundColor = UIColor.blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smallSquare.frame = CGRect(x: 0, y: 0, width: 40, height: 40) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smallSquare.frame = CGRect(x: 20, y: 20, width: 80, height: 80) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView.animate(withDuration: 1) { | |
smallSquare.layer.position = CGPoint(x: 60, y: 60) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView.animate(withDuration: 1) { | |
myView.frame = CGRect(x: 60, y: 60, width: 100, height: 100) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView.animate(withDuration: 1) { | |
smallSquare.layer.position = CGPoint(x: 60, y: 60) | |
smallSquare.transform = CGAffineTransform.identity.scaledBy(x: 2, y: 2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func animateTo(frame: CGRect, withDuration duration: TimeInterval, completion: ((Bool) -> Void)? = nil) { | |
guard let _ = superview else { | |
return | |
} | |
let xScale = frame.size.width / self.frame.size.width | |
let yScale = frame.size.height / self.frame.size.height | |
let x = frame.origin.x + (self.frame.width * xScale)/2 | |
let y = frame.origin.y + (self.frame.height * yScale)/2 | |
UIView.animate(withDuration: duration, delay: 0, options: .curveLinear, animations: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smallSquare.animateTo(frame: CGRect(x: 60, y: 60, width: 80, height: 80), withDuration: 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x = frame.origin.x + (self.frame.width * xScale)/2 | |
let y = frame.origin.y + (self.frame.height * yScale)/2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x = frame.origin.x + (self.frame.width * xScale) * self.layer.anchorPoint.x | |
let y = frame.origin.y + (self.frame.height * yScale) * self.layer.anchorPoint.y |
OlderNewer