If the image goes off the screen, it is itself removed from the system (memory) or for this you need to use
{ animationFinished in self.gor.removeFromSuperview() }) to remove?

 gor = UIImageView(frame:CGRectMake(300, 0, 150, 350)) gor.image = UIImage(named: "gor0002b.png") self.view.addSubview(gor) UIView.animateWithDuration(0.5, animations: { self.gor.frame = CGRect(x:-200, y: 750, width: 350, height: 530) }, completion: nil}) 

    2 answers 2

    An object is in memory while it has at least one owner, in other words, while its retainCount is> 0. In your case, adding an object to the subview array of a view increases its retainCount by 1, and to remove the object from memory (provided that he has no other owners) it must be removed from the array view.subviews by executing -removeFromSuperview .

    The position of the view on the screen does not affect this mechanism.

    • when I do {animationFinished in self.gor.removeFromSuperview ()} - after one cycle, everything ends (the animation starts on a timer with a repeat ...) added options: .Repeat - UIView.animateWithDuration (1.0, delay: 0.0, options: [.Repeat], animations: {self.addView.frame = CGRect (x: -380, y: 525, width: 400, height: 80)}, completion: {animationFinished in self.addView.removeFromSuperview ()}) - the same one cycle and that's it ... something goes wrong .... @ Max Mikheyenko - user198638

    The object will live while the parent is alive, regardless of whether it is visible or not. Swift cannot know whether he will need you later or not.

    • but sorry ... thanks @iosp - user198638