5

我被一个非常简单的任务难住,我想要一个UIView动画来缓解/缓解,但它总是线性的,尽管使用了正确的animationOption。UIView动画曲线不起作用easenout

这里是所有帐户都应该工作的代码,它被设置在UIViewControllerAnimatedTransitioning类中,但我在以前的自定义segue类中存在相同的问题;

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 

     self.dimView.alpha = 1.0; 
     self.imageView.frame = self.destinationRect; 

    } completion:^(BOOL finished) { 

     [self.imageView removeFromSuperview]; 
     [self.dimView removeFromSuperview]; 

     [transitionContext completeTransition:YES]; 

    }]; 

但是,以下代码的弹簧动画虽然可以工作,但我宁愿不这样做。

[UIView animateWithDuration:0.8f delay:0 usingSpringWithDamping:0.7f initialSpringVelocity:2.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 

     self.dimView.alpha = 1.0; 
     self.imageView.frame = self.destinationRect; 

    } completion:^(BOOL finished){ 

     [self.imageView removeFromSuperview]; 
     [self.dimView removeFromSuperview]; 

     [transitionContext completeTransition:YES]; 

    }]; 

我在模拟器和iPad2测试设备上获得了相同的行为。 我做错了什么? 动画框架或alpha值有问题吗?

回答

3

你可以试试这个instead.-

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDuration:0.4f]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop)]; 

self.dimView.alpha = 1.0; 
self.imageView.frame = self.destinationRect; 

[UIView commitAnimations]; 

- (void) animationDidStop { 
    [self.imageView removeFromSuperview]; 
    [self.dimView removeFromSuperview]; 
    [transitionContext completeTransition:YES]; 
} 

希望它能帮助。

+0

谢谢ssantos。起初我以为它做到了,但我的眼睛在愚弄我。绝对是线性的。非常奇怪和烦人。 –

+0

确实很奇怪,可能距离太小,不能注意到区别?为了以防万一,我会尝试使用不同“animationCurves”的“大型”动画。 – ssantos

1

您可以使用以下方法:

[自转变:左]。 //调用所需

enum animationFrom { 
    top, 
    bottom, 
    left, 
    right 
}; 

- (void)transition:(NSUInteger)index { 
    CATransition *tr=[CATransition animation]; 
    tr.duration=0.45; 
    tr.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    tr.type=kCATransitionPush; 
    tr.delegate=self; 
    switch (index) { 
     case top: 
      tr.subtype=kCATransitionFromBottom; 
      break; 
     case bottom: 
      tr.subtype=kCATransitionFromTop; 
      break; 
     case left: 
      tr.subtype=kCATransitionFromRight; 
      break; 
     case right: 
      tr.subtype=kCATransitionFromLeft; 
      break; 
     default: 
      break; 
    } 
    [self.view.layer addAnimation:tr forKey:nil]; 
} 
1

默认动画曲线选项UIViewAnimationOptionCurveEaseInOut,所以您不需要指定这一个。你必须明确的是UIViewAnimationOptionCurveLinear

你确定你的动画曲线是线性的吗?尝试将两个视图动画化,将动画持续时间设置为几秒。