ios - UIView Animation happens faster than specified seconds -


i have view image shows text in it. need perform animation reveals character character in end complete text has displayed.

i have logo view in interface, on have animate view. animate view leading, trailing, top , bottom constraints set based on superview (logo view).

i have tried following code duration have specified not working properly.

   - (void) animatelogo {     [uiview animatewithduration:10.0 animations:^{         nslog(@"animation started");         if (self.animateviewleadingconstraint.constant < 94) { //94 total width of logo view             self.animateviewleadingconstraint.constant = self.animateviewleadingconstraint.constant + 1;         } else {             self.animateviewleadingconstraint.constant = 0;         }     } completion:^(bool finished) {         nslog(@"animation ended");         [self.animateview layoutifneeded];         [self animatelogo];     }]; } 

i have attached log time duration

2016-08-01 17:55:27.317 sample[20361:481531] animation started 2016-08-01 17:55:27.318 sample[20361:481531] animation ended 2016-08-01 17:55:27.318 sample[20361:481531] animation started 2016-08-01 17:55:27.318 sample[20361:481531] animation ended 2016-08-01 17:55:27.318 sample[20361:481531] animation started 2016-08-01 17:55:27.319 sample[20361:481531] animation ended 2016-08-01 17:55:27.319 sample[20361:481531] animation started 2016-08-01 17:55:27.319 sample[20361:481531] animation ended 

i not sure mistake have made in above code or misunderstood uiview animation concept

any or hint appreciated.

see answer: how animate constraint changes?

you should calling layoutifneeded on animated view's superview before animation block, , in animations: block itself. first call makes sure layout changes applied. assuming logoview superview of animateview:

- (void) animatelogo {     self.animateviewleadingconstraint.constant = 0.0;     [self.logoview layoutifneeded];     [uiview animatewithduration:10.0 animations:^{         nslog(@"animation started");         self.animateviewleadingconstraint.constant = 94.0;         [self.logoview layoutifneeded];     } completion:^(bool finished) {         nslog(@"animation ended");     }]; } 

Comments