我点击单击条形按钮时向下滑动UIView。到目前为止,这么好,但我遇到了一个问题。为了美观,我在视图中添加了一个底部边框,我想用UIView滑动动画为这个底部边框设置动画。问题是CABasicAnimation是有限的,不允许使用CurveEaseIn。因此,底部边框比UIView滑动得更快。
我该如何解决这个问题?
[UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
_navView.frame = CGRectMake(0, 0, 320, 350);
_navView.frame = CGRectMake(0, 0, 320, 350);
CALayer *oldLayer = [[_navView.layer sublayers] lastObject];
CGRect oldFrame = oldLayer.frame;
CGRect newFrame = oldFrame;
newFrame.origin = CGPointMake(0, 350);
// Prepare the animation from the old size to the new size
CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"frame"];
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theAnimation.duration = .5;
// Make this view controller the delegate so it knows when the animation starts and ends
theAnimation.delegate=self;
// Use fromValue and toValue
theAnimation.fromValue = [NSValue valueWithCGRect:oldFrame];
theAnimation.toValue = [NSValue valueWithCGRect:newFrame];
// Update the frame of the layer
oldLayer.frame = newFrame;
// Add the animation to the layer
[oldLayer addAnimation:theAnimation forKey:@"frame"];
} completion:^(BOOL finished) {
}];
答案 0 :(得分:0)
最简单的解决方案几乎可以肯定是为底部边框使用视图而不是图层,然后使用UIKit而不是Core Animation为边框视图设置动画。