0
我試圖在單擊欄按鈕時滑下UIView。到目前爲止,這麼好,但我遇到了一個問題。爲了美觀,我在視圖中添加了底部邊框,並且我想用UIView滑動動畫爲底部邊框設置動畫。問題是CABasicAnimation是有限的,不允許CurveEaseIn。所以,下邊框比UIView更快。用CALayer下邊框向下滑動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) {
}];