Question

At normal state UI is like follow

enter image description here

when tableview slide up, i want the navigationBar became small with animation. Code like follow

CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"transform"];
shake.duration = DURATION_TIME;

shake.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0 ,1.0)];
shake.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 0.5, 1.0)];

shake.removedOnCompletion = NO;
shake.fillMode = kCAFillModeForwards;

[self.navigationController.navigationBar.layer addAnimation:shake forKey:@"shakeAnimation"];

after the animation UI like follow

enter image description here

I don't want the navigationBar's y position change. And the titleView and rightbarItem became flat, How to avoid them becomes flat?

Was it helpful?

Solution

Try the code below. It works before ios7

UIView * testView = self.navigationController.navigationBar ;
CGRect frame = testView.layer.frame ;
testView.layer.anchorPoint = CGPointMake(0.5f, 0.0f) ;
testView.layer.frame = frame ;

[UIView animateWithDuration:1.0 animations:^{
    CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"transform"];
    shake.duration = 1.0;

    shake.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0 ,1.0)];
    shake.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 0.5, 1.0)];

    shake.removedOnCompletion = NO;
    shake.fillMode = kCAFillModeForwards;

    [testView.layer addAnimation:shake forKey:@"shakeAnimation"];
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top