当应用活动处于活动状态时,ImageView不会恢复动画



我正在对图像视图进行动画视图。如果我点击图像,它应该被翻转,然后动画应启动。一切正常,但是如果应用程序在敲击图像后进行背景,则它不会恢复动画。

[UIView animateWithDuration:0.8 delay:0.2 options:UIViewAnimationOptionTransitionNone animations:^{
             ImageView.layer.transform = CATransform3DMakeRotation(M_PI/2, -1, 1, 0);
        } completion:^(BOOL finished) {

            [UIView animateWithDuration:0.7 delay:0.0 options:UIViewAnimationOptionTransitionNone animations:^{
                ImageView.layer.transform = CATransform3DMakeRotation(0, 0, 1, 1);
                [_aCardImageView setImage:[UIImage imageNamed:[imageArray objectAtIndex:index_value]]];
            }
             completion:^(BOOL finished){
                [_aCardImageView setImage:[UIImage imageNamed:[_back_imageArray objectAtIndex:index_value]]];
                [ImageView setUserInteractionEnabled:NO];
                    CGRect frame = [[Frames_array objectAtIndex:index_value]CGRectValue];
                    [self lip_sequence:index_value :frame];
           }
}];

这是应用程序移动到后台时删除的默认行为。因此,您需要保存动画状态并手动恢复。

如果您想这样做,则需要收听ApplicationDidenterBackground和Application WillenterForeground Noctifations并在其上处理动画。

您可以在输入背景上节省图层或动画,然后恢复前景。

要恢复动画,您可以从Apple中使用此示例代码:https://developer.apple.com/library/ios/qa/qa1673/_index.html

也有一个好人将此任务包裹在卡莱耶的不错类别中,因此您可以使用一线:

[view.layer MB_setCurrentAnimationsPersistent];

保存所有图层动画或

view.layer.MB_persistentAnimationKeys = @[@"position"]; 

仅保存所需的动画。

最新更新