2014-09-26 24 views
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) { 
    }]; 

回答

0

最简单的方案几乎可以肯定是使用视图,而不是一个层,你的下边框,然后使用,而不是核心动画UIKit的动画边框视图。