简体   繁体   English

iOS:+ [UIView animateWithDuration:]未使用持续时间

[英]iOS: +[UIView animateWithDuration:] not utilizing the duration

I'm trying to animate the movement of a view "falling" to the bottom of the iPad screen, with a little bounce at the end. 我正在尝试使视图“下降”到iPad屏幕底部的动画效果,最后有一点反弹。

The bouncing effect is fine. 弹跳效果很好。 My problem is that the "falling" animation isn't working at all like it's supposed to. 我的问题是,“下降”动画根本无法正常运行。

I want the animation to be linear. 我希望动画是线性的。 (I know; "falling" isn't linear, but I think it's fine in my case.) It seems to be doing ease in-ease out. (我知道;“下降”不是线性的,但对于我而言,这是很好的。)似乎可以轻松实现“缓入”。 The bigger problem is that I want it to be done in the duration I specify. 更大的问题是我希望在指定的时间内完成此操作。 It isn't. 不是。 If distance is small, say 100 pixels, the duration computes to 0.1 seconds, and it seems to take about 0.1 seconds. 如果距离很小,例如100像素,则持续时间将计算为0.1秒,似乎需要大约0.1秒。 But if the distance is large, say, 1000 pixels, the duration should be 1 second, but it's much longer: about 3 seconds. 但是,如果距离很大(例如1000像素),则持续时间应该为1秒,但会更长:大约3秒。

Any ideas? 有任何想法吗? Here's the code: 这是代码:

NSTimeInterval duration = (distanceToTravel / (float)1000);
NSLog(@"distance = %f, duration = %f", distanceToTravel, duration);
[UIView animateWithDuration:duration delay:0 options:(UIViewAnimationCurveLinear) animations:^ {
        wpcvc.view.center = wpcvc.startingDragLocation;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.2 delay:0 options:( UIViewAnimationCurveEaseOut) animations:^ {
            wpcvc.view.center = CGPointMake(wpcvc.startingDragLocation.x, wpcvc.startingDragLocation.y - 2);
        } completion:^(BOOL finished2) {
            [UIView animateWithDuration:0.2 delay:0 options:(UIViewAnimationCurveEaseIn) animations:^ {
                wpcvc.view.center = wpcvc.startingDragLocation;
            } completion:^(BOOL finished3) {
            }];
        }];
    }];

Any assistance is appreciated! 任何帮助表示赞赏!

You shouldn't use the UIViewAnimationCurveLinear option for UIView.animateWithDuration 您不应该将UIViewAnimationCurveLinear选项用于UIView.animateWithDuration

For linear animation you have to use the options of UIViewAnimationOptions, in your case is this UIViewAnimationOptionCurveLinear (please note the Option -difference): 对于线性动画,您必须使用UIViewAnimationOptions的选项,在这种情况下,请使用以下UIViewAnimationOptionCurveLinear(请注意Option -difference):

[UIView animateWithDuration:duration delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^ {
    wpcvc.view.center = wpcvc.startingDragLocation;
} completion:^(BOOL finished) {
    [UIView animateWithDuration:0.2 delay:0 options:( UIViewAnimationOptionCurveEaseOut) animations:^ {
        wpcvc.view.center = CGPointMake(wpcvc.startingDragLocation.x, wpcvc.startingDragLocation.y - 2);
    } completion:^(BOOL finished2) {
        [UIView animateWithDuration:0.2 delay:0 options:(UIViewAnimationOptionCurveEaseIn) animations:^ {
            wpcvc.view.center = wpcvc.startingDragLocation;
        } completion:^(BOOL finished3) {
        }];
    }];
}];

Just to make sure, have you turned off slow animations? 只是为了确保您关闭了慢动画? The simulator has a slow animations debug setting (which I occasional accidentally toggle). 模拟器的动画调试设置很慢(我偶尔不小心切换了该设置)。

在此处输入图片说明

Are you doing this in a place that already has implicit animation, such as viewWillAppear:, viewDidAppear:, etc? 您是在已经具有隐式动画的地方(例如viewWillAppear:,viewDidAppear:等)执行此操作吗? If so that could be messing with the settings of your first animation as everything in there is within an animation block. 如果是这样,那可能会使第一个动画的设置混乱,因为其中的所有内容都在动画块内。

'wpcvc' is added to no superview? 'wpcvc'被添加到没有超级视图? (or super-superview so?) (还是超级超级观看?)

[(superview) addSubview:wpcvc];
[UIView animateWithDuration:...

It is necessary for target view to be added to some superview beforehand. 必须事先将目标视图添加到某些超级视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM