Im trying to make items spawn at the location of the cloud. So far I have the cloud animating on repeat just how i want it, but when I spawn an item the cloud animation resets from the beginning.
when adding a subview
, What are my options?
Here is a gif from the project
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
gemCloudImage.center.x = 100
makeCloudFly()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
}
func makeCloudFly() {
UIView.animateWithDuration(6, delay: 1, options: [.Autoreverse, .Repeat], animations: {
self.gemCloudImage.center.x = self.view.frame.width - 100
}, completion: nil)
}
@IBAction func buttonTapped(sender: AnyObject) {
let positionX: CGFloat = gemCloudImage.layer.presentationLayer()!.frame.midX
let positionY: CGFloat = gemCloudImage.layer.presentationLayer()!.frame.midY
print(positionX)
print(positionY)
let chair = UIImageView()
chair.image = UIImage(named: "CHAIR1")
chair.frame = CGRectMake(positionX, positionY, 50, 50)
chair.frame = CGRect(x:positionX, y:positionY, width:50, height:50)
self.view.addSubview(chair)
}