【问题标题】:UIViewAnimation plays instantly, delay is ignoredUIViewAnimation 立即播放,延迟被忽略
【发布时间】:2012-11-15 15:35:59
【问题描述】:

我有一个简单的 UIViewAnimation,一旦我的视图被加载,它就会被调用。 但是,无论我设置什么作为延迟值,它都会被忽略并且动画会立即播放。

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:100.0];
[UIView setAnimationDelay:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(faceRight:finished:context:)];
_chooseLabelContainer.center = CGPointMake(originalCenter.x, 0 - _chooseLabelContainer.frame.size.height);
[UIView commitAnimations];

更新:作为一项测试,我已经处理了这种情况,并且在非延迟动画下方会立即发生,但是调度队列中的动画会按预期超时! UIView* objectToAnimate = self.hudController->_chooseLabelContainer;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
    [UIView animateWithDuration:5.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        NSLog(@"Start Dispatch %@", NSStringFromCGPoint( objectToAnimate.center ) );
        objectToAnimate.center = CGPointMake(objectToAnimate.center.x, objectToAnimate.center.y+90);
    }completion:^(BOOL done){
        NSLog(@"Done Dispatch");
    }];


});

[UIView animateWithDuration:5.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
    NSLog(@"Start %@", NSStringFromCGPoint( objectToAnimate.center ) );
    objectToAnimate.center = CGPointMake( objectToAnimate.center.x, objectToAnimate.center.y+30);
}completion:^(BOOL done){
    NSLog(@"Done");
}];

【问题讨论】:

    标签: ios uiview uiviewanimation


    【解决方案1】:

    这可能无法解决您的问题,但从 iOS 4 开始,Apple 建议您使用 UIView 动画块:

    [UIView animateWithDuration:100.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        _chooseLabelContainer.frame = CGPointMake(originalCenter.x, 0 - _chooseLabelContainer.frame.size.height);
    }completion:^(BOOL done){
        [self faceRight:finished:context]; //will of course generate errors since I don't know what arguments to pass.
    }];
    

    【讨论】:

    • 出现同样的问题 :( - 我本来就有这个问题,但在调试过程中只是切换到“旧方式”。
    • 这个视图控制器转换后,在viewDidAppear函数上
    • 另外需要注意的是,动画没有动画,它会立即将对象放置到位。为了调试,我还将上面的代码放在触摸处理程序中 - 每当我点击时,指定的视图就会跳转到新位置
    • @1dayitwillmake 最初您的代码包含_chooseLabelContainer.frame,现在我看到您已将其编辑为_chooseLabelContainer.center。如果您仍在代码中使用 .frame,则向 CGRect 发送 CGPoint 可能会导致此问题。
    • 是的,这是我粘贴之前 cmd+z 的错字。如果重要的话,我有一个 GLView 与这个视图的背后同时存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多