【问题标题】:block animations: set UIViewAnimationOptionCurveLinear块动画:设置 UIViewAnimationOptionCurveLinear
【发布时间】:2011-04-03 15:41:35
【问题描述】:

抱歉,这是非常基本的,但我无法将 AnimationOption 从默认 (EaseIn) 设置为 CurveLinear。这是我根据我在其他线程中阅读的内容所尝试的:

    -(void)animationShadow;
{
    [UIView animateWithDuration:4
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
...

如果我去掉选项位,一切正常。如果没有,它会崩溃。我确定我没有调用正确的命令。

这是整个方块动画:

   -(void)animationShadow;
{
    [UIView animateWithDuration:4
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{

        //UIViewAnimationOptionCurveLinear

        // animation 1
        [pageShadowView setTransform:CGAffineTransformMakeScale (3, 1)];
        [pageShadowView setFrame:CGRectMake(0-350, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];

        [UIView beginAnimations:@"pageCurlRightToLeftFinished" context:nil]; // Begin animation
        //[UIView setAnimationCurve:UIViewAnimationCurveLinear];
        [pageShadowView setFrame:CGRectMake(0-280, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
        [UIView commitAnimations];



    } completion:^(BOOL finished){ ...

编辑:

好的,我现在更新了这个,但是如果我做第二个动画,我仍然会崩溃。我收到警告:UIView 可能无法响应 +animateWithDuration ...:

-(void)动画阴影; {

[pageShadowView setTransform:CGAffineTransformMakeScale (3, 1)];
[pageShadowView setFrame:CGRectMake(0-350, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];


[UIView animateWithDuration:kPageCurlSpeed/4
                      delay:0
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{
            [pageShadowView setFrame:CGRectMake(0-280, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
                            }
                 completion:^(BOOL finished){


                     [UIView animateWithDuration:kPageCurlSpeed
                                           delay:0
                                         options:UIViewAnimationOptionCurveLinear
                                      animations:^{
                                          // animation 2

                                          [pageShadowView setTransform:CGAffineTransformMakeScale (0.1, 1)];
                                          [pageShadowView setFrame:CGRectMake((340-pageShadowView.frame.size.width), 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];

                                      }
                      ]; // this is where I get the warning!!



                     }];

}

【问题讨论】:

    标签: iphone objective-c cocoa-touch animation uiview


    【解决方案1】:

    编辑:动画初始化代码应该放在动画块之外。该块指定视图在动画结束时应达到的最终状态。

    [pageShadowView setTransform:CGAffineTransformMakeScale(3, 1)];
    [pageShadowView setFrame:CGRectMake(-350, ...)];
    
    [UIView animateWithDuration:4 delay:0
                        options:UIViewAnimationOptionCurveLinear 
                     animations:^{
                                  [pageShadowView setFrame:CGRectMake(-280, ...)];
                                }
                     completion:NULL];
    

    如果你想连续运行 2 个动画,第 2 个应该放在 completion 块中。

    [UIView animateWithDuration:4 delay:0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{ /* animation 1 */ }
                     completion:^(BOOL finished) {
                                   /* animation 2 */
                                }];
    

    【讨论】:

    • @KeenyTM:感谢您的回复。嗯,实际上,这就是我想要做的。我刚刚在这里展示了第一个动画。我是否需要将 [pageShadowView setTransform... 等直到 [UIView commitAnimations];进入你标记为 /* 动画 1 */?我想我还没有得到块动画的概念。你是说我在上面的代码中有两个动画吗?我只是试图定义动画的起点(x= -350)和终点(x = -280),所以我认为这只是一个动画,即从 x=-350 到 x=-280。感谢您的帮助!
    • @KennyTm:非常感谢您的帮助。我想我现在明白了这个概念,但我仍然不确定第二个动画。我更新了我的代码——请参见上文——它仍然崩溃。我确定我没有按我应该的方式启动第二个动画。
    • @n.ever:你错过了delay:0
    • @KennyTm:我仍然得到 UIView 可能无法响应 +animateWithDuration ...:警告在 ];从底部开始的三行(我在上面做了标记)。我错过了什么?很抱歉这么痛苦。 [UIView animateWithDuration:kPageCurlSpeed delay:0 options:UIViewAnimationOptionCurveLinear animations:^{ // ... } ]; 应该做这个工作,不是吗?
    • @n.ever:所有 5 个参数(持续时间、延迟、选项、动画、完成)都是必需的。即使它是 NULL 或 0,您也不能省略或重新排序它们中的任何一个。这通常适用于所有 Objective-C 方法。
    【解决方案2】:

    如果您发现您选择的曲线被忽略,请检查您是否使用了正确的开关组。

    有一种叫做 UIViewAnimationCurveLinear(用于旧方法)和 UIViewAnimationOptionCurveLinear(用于块方法),并且很容易将它们混合在一起。有相应的等价对,用于缓入、缓出等。

    这引起了我的注意,所以我想我会确保其他人可以轻松看到这些信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多