facebookarchive / pop

An extensible iOS and OS X animation library, useful for physics-based interactions.
Other
19.66k stars 2.88k forks source link

Layer issue when animating textfield in navigation bar #298

Closed olivierto closed 8 years ago

olivierto commented 8 years ago

Hello there ! I'm facing a weird issue with an animation of a textfield inside a navigationItem. I'm moving the title in navbar and replace it with a search text Field. Here is my code :

POPSpringAnimation *positionTitleViewAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
    UILabel *titleLabel = (UILabel *)self.navigationItem.titleView;
    positionTitleViewAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(-600, 10)];
    [positionTitleViewAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
        self.navigationItem.titleView = nil;
        [self.navigationItem setTitleView:self.searchTextField];
        POPSpringAnimation *sizeTextAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleX];
        sizeTextAnimation.toValue = @(self.navigationController.navigationBar.frame.size.width);
        [sizeTextAnimation setCompletionBlock:^(POPAnimation *animation, BOOL finished2) {
            [self.searchTextField becomeFirstResponder];
        }];
        [self.searchTextField.layer pop_addAnimation:sizeTextAnimation forKey:@"sizeTextAnime"];

    }];
    [titleLabel  pop_addAnimation:positionTitleViewAnimation forKey:@"positionTitleViewAnimation"];

Here is the result : simulator screen shot 2 janv 2016 17 20 03

Any help would be much appreciated.

grp commented 8 years ago

You're using the animation property kPOPLayerScaleX, which corresponds to the CALayer key path transform.scale.x, where 1.0 is the identity scale. However, in this case you're scaling it to a toValue of self.navigationController.navigationBar.frame.size.width, which is presumably quite large, perhaps 320. So your view will end up 320 times as wide as it started out — probably more stretched out than you were hoping!

I'd try using kPOPLayerSize if you just want to change the layer's bounds, or a lower toValue if you really do want to change the scale. I'd also suggest messing around with the values without using Pop at all, to make sure the final result the animation is going towards is what you expect before setting it up with an animation.

olivierto commented 8 years ago

sorry for late reply! ok! i misunderstood that i was manipulating the scale factor ! So i used the kPopLayerSize and all works great :) many thanks! Bye!