Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 模拟视图反弹?_Ios_Iphone_Cocoa Touch_Uikit_Core Animation - Fatal编程技术网

Ios 模拟视图反弹?

Ios 模拟视图反弹?,ios,iphone,cocoa-touch,uikit,core-animation,Ios,Iphone,Cocoa Touch,Uikit,Core Animation,在iPhone上模拟UIAlertView中反弹动画的最佳方式是什么?有什么内在的机制吗?UIAlertView本身无法满足我的需要 我查看了动画曲线,但从中可以看出,它们提供的唯一动画是easeIn、easeOut和linear。您可以使用两个动画,一个用于弹出非常大的动画,另一个用于重新缩放回正常大小 (这是UIAlertView内部使用的方法。) 或者,您可以使用较低级别的CAAnimation并使用+[camediatiming function with controlpoints::

在iPhone上模拟UIAlertView中反弹动画的最佳方式是什么?有什么内在的机制吗?UIAlertView本身无法满足我的需要


我查看了动画曲线,但从中可以看出,它们提供的唯一动画是easeIn、easeOut和linear。

您可以使用两个动画,一个用于弹出非常大的动画,另一个用于重新缩放回正常大小

(这是
UIAlertView
内部使用的方法。)


或者,您可以使用较低级别的
CAAnimation
并使用
+[camediatiming function with controlpoints:::]
创建自己的曲线。

UIAlertView使用更复杂的动画:

  • 缩放到大于100%
  • 缩放到小于100%
  • 比例为100%
下面是一个使用
cakeyKeyMeanimation
的实现:

view.alpha = 0;
[UIView animateWithDuration:0.1 animations:^{view.alpha = 1.0;}];

CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
bounceAnimation.values = @[@0.01f, @1.1f, @0.8f, @1.0f];
bounceAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
bounceAnimation.duration = 0.4;
[view.layer addAnimation:bounceAnimation forKey:@"bounce"];

我研究了如何通过滑动
-[CALayer addAnimation:forKey://code>将动画添加到
UIAlertView
的层中。以下是它执行的缩放变换动画的值:

0.01f->1.10f->0.90f->1.00f

有持续时间

0.2s、0.1s、0.1s

所有动画都使用缓进/缓出计时功能。下面是一个封装此逻辑的
CAKeyframeAnimation

CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
bounceAnimation.fillMode = kCAFillModeBoth;
bounceAnimation.removedOnCompletion = YES;
bounceAnimation.duration = 0.4;
bounceAnimation.values = @[
    [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 0.01f)],
    [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.1f)],
    [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 0.9f)],
    [NSValue valueWithCATransform3D:CATransform3DIdentity]];
bounceAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
bounceAnimation.timingFunctions = @[
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

我相信
UIAlertView
也会在变换动画的整个持续时间(
0.4
)内执行一个简单的不透明度动画,从
0.0f
1.0f

以下是我为正在开发的应用程序所做的。当你按下视图时,我想要的效果是反弹。尝试这些值,以满足您的口味和所需的效果速度

- (void) bounceView:(UIView*)bouncer
{
    // set duration to whatever you want
    float duration = 1.25;
    // use a consistent frame rate for smooth animation.
    // experiment to your taste
    float numSteps = 15 * duration;

    // scale the image up and down, halving the distance each time
    [UIView animateKeyframesWithDuration:duration
                                   delay:0
                                 options:UIViewKeyframeAnimationOptionCalculationModeCubic
                              animations:^{
                                  float minScale = 0.50f; // minimum amount of shrink
                                  float maxScale = 1.75f; // maximum amount of grow
                                  for(int i = 0; i< numSteps*2; i+=2)
                                  {
                                      // bounce down
                                      [UIView addKeyframeWithRelativeStartTime:duration/numSteps * i
                                                              relativeDuration:duration/numSteps
                                                                    animations:^{
                                                                        bouncer.layer.transform = CATransform3DMakeScale(minScale, minScale, 1);
                                                                    }];
                                      // bounce up
                                      [UIView addKeyframeWithRelativeStartTime:duration/numSteps * (i+1)
                                                              relativeDuration:duration/numSteps
                                                                    animations:^{
                                                                        bouncer.layer.transform = CATransform3DMakeScale(maxScale, maxScale, 1);
                                                                    }];

                                      // cut min scale halfway to identity
                                      minScale = minScale + (1.0f - minScale) / 2.0f;
                                      // cut max scale halfway to identity
                                      maxScale = 1.0f + (maxScale - 1.0f) / 2.0f;
                                  }
                              } completion:^(BOOL finished) {
                                  // quickly smooth out any rounding errors
                                  [UIView animateWithDuration:0.5*duration/numSteps animations:^{
                                      bouncer.layer.transform = CATransform3DIdentity;
                                  }];
                              }];
}
-(无效)bounceView:(UIView*)弹跳器
{
//将持续时间设置为您想要的任何时间
浮动持续时间=1.25;
//为平滑动画使用一致的帧速率。
//按你的口味做实验
浮点numSteps=15*持续时间;
//上下缩放图像,每次将距离减半
[UIView animateKeyframesWithDuration:持续时间
延迟:0
选项:UIViewKeyframeAnimationOptionCalculationModelCubic
动画:^{
float minScale=0.50f;//最小收缩量
float maxScale=1.75f;//最大增长量
对于(int i=0;i
谢谢!这很有帮助。谢谢,谢谢,谢谢。我已经为此挣扎了一段时间。这取决于个人喜好。但我提供的关键时刻正是
UIAlertView
所使用的。