隐藏拆分视图控制器的母版时(在纵向模式下),核心动画会停止吗? [英] Core animation stops when the Master of the split viewcontroller hide (in portrait mode)?

查看:76
本文介绍了隐藏拆分视图控制器的母版时(在纵向模式下),核心动画会停止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将闪烁的动画应用于splitviewController的First viewController中的 tableViewcell contentView 。我的问题是,当我隐藏带有splitViewController的 presentsWithGesture 属性的FirstViewcontroller

I applied the blinking animation to the contentView of the tableViewcell for a table in First viewController of the splitviewController. My problem is, the animation stops when I hide the FirstViewcontroller with presentsWithGesture property of splitViewController

我已经将UItableViewCell和我在设置属性时添加了动画,而
则将动画添加到了单元格 contentView 中,如下所示

I have subclassed UItableViewCell and I add animation while setting a property and I added the animation to the contentView of cell like below

-(void)setProperty:(Property *)aProperty
{
    _property=aProperty;
    [self.contentView addSubview:self.dateLabel];
    self.dateLabel.text=[self.meeting stringforScheduleDate];
    if (_property.opened) {
        CABasicAnimation *theAnimation;
        CALayer *layer=[self.contentView layer];
        theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
        theAnimation.duration = 0.5;
        theAnimation.delegate=self;
        theAnimation.fromValue = [NSNumber numberWithFloat:0.0];
        theAnimation.toValue = [NSNumber numberWithFloat:1.0];
        theAnimation.repeatCount=HUGE_VALF;
        theAnimation.autoreverses=YES;
//        [layer removeAnimationForKey:@"opacity"];
        [layer addAnimation:theAnimation forKey:@"opacity"];
    }
    else
    {
        CALayer *layer=[self.contentView layer];
        [layer removeAnimationForKey:@"opacity"];
    }
}

我不知道ViewController的行为是否隐藏时,请在其视图层次结构中停止核心动画,或者我是否错过了代码。因此,请帮助我同行

I don't know whether it is ViewController's behavior to stop core animation in it's view hierarchy when hidden or do I have missed something in my code. So help me out peers

推荐答案

是的,动画已从视图的图层一旦其视图控制器被隐藏。奇怪的是,即使 view.layer.animationKeys.count == 0 ,有时动画也可以持续,但通常不会。

Yes, the animations are removed from the view's layer once its view controller is hidden. Strangely, sometimes the animation can persist even if view.layer.animationKeys.count == 0, but usually not.

您最好的选择是在 -viewWillAppear: -viewDidAppear: ...中为@vignesh_kumar启动动画,也许可以通过类似这样的方法:

Your best bet is to start the animations in -viewWillAppear: or -viewDidAppear:... for @vignesh_kumar, perhaps through a method like:

- (void)startAnimations
{
    NSArray *visibleCells = self.tableView.visibleCells;
    for (CustomTableViewCell *cell in visibleCells) {
        [cell animateIfNeeded];
    }
}

@doNotCheckMyBlog,在这里您可以调用开始的方法 headerView 的动画。

@doNotCheckMyBlog, here you could call the method that starts the headerView's animation.

除此之外,我猜测动画也将停止

In addition to that, I'm guessing that the animations will also be stopped if you background the app and then resume it.

您还需要调用 -startAnimations 方法。应用程序恢复。例如,您的应用程序委托可以在 -applicationDidBecomeActive:-中发送 NSNotification applicationWillEnterForeground:方法。您的 MasterViewController 可以观察此通知,并在收到通知时调用 -startAnimations

You will also need to call the -startAnimations method when the app resumes. For example, your app delegate could send out an NSNotification in its -applicationDidBecomeActive: or -applicationWillEnterForeground: method. Your MasterViewController could observe this notification and call -startAnimations when it receives it.

如果您不需要在动画中返回相同的确切状态,那么这应该不是一个大问题。如果需要在动画中返回与应用程序背景化时相同的状态,那么还需要保存该状态,然后在重新启动动画时设置初始状态。

If you don't need to return to the same exact state in the animation, then this shouldn't be a huge problem. If you need to return to the same state in the animation as it was in when the app was backgrounded, then you'll also need to save the state and then set the initial state when you restart the animation.

这篇关于隐藏拆分视图控制器的母版时(在纵向模式下),核心动画会停止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆