在正常状态下,用户界面就像是
当tableview向上滑动时,我希望navigationBar变小,带动画。 代码如下
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"];
在动画UI之后如下
我不希望navigationBar的y位置发生变化。并且titleView和rightbarItem变得扁平,如何避免它们变平?
答案 0 :(得分:0)
尝试以下代码。它适用于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"];
}];