1

I have some Labels in xib file, which were sett up by constrains. But I want to make some easy animations. Here is idea: set elements out of screen then user open aplication and then animate it back. So problem is: to make elements out of screen, I implemented following code in viewWillAppear method, but it doesnt work:

-(void)viewWillAppear:(BOOL)animated{
    CGFloat correction = self.view.bounds.size.width;
    CGPoint center1 = self.icon.center;
    center1.x += correction;
    self.icon.center = center1;
}

and my animation code in viewDidAppear method:

[UIView animateWithDuration:0.8
                       delay:0.1
      usingSpringWithDamping:1.0
       initialSpringVelocity:1.0
                     options:UIViewAnimationOptionCurveEaseInOut
                  animations:^{

                      CGFloat correction = self.view.bounds.size.width;
                      CGPoint center1 = self.icon.center;
                      center1.x -= correction;
                      self.icon.center = center1;

} completion:^(BOOL finished) {
                          NSLog(@"ready");
                      }];

but if I paste code from viewWillAppear to viewDidAppear it works. But a bit weird. How to make it right?

nayem
  • 7,285
  • 1
  • 33
  • 51
Ilya Chikmarev
  • 133
  • 1
  • 11
  • put your code in `viewDidLayoutSubView` – Dhiru Apr 24 '17 at 10:04
  • Do not set the frame of your views manually... frames are calculated by the autolayout engine and any interference outside that will brake your layout. So you are left with 2 options: 1. Animate the constraints instead (if your animation will affect other views), 2. Animate a transform (a translation in your case) in order to animate _only_ the [presentation layer](https://www.objc.io/issues/12-animations/animations-explained/) – Alladinian Apr 24 '17 at 11:24

0 Answers0