当分割视图控制器的主人隐藏(纵向模式)时,核心动画停止?

vig*_*mar 2 core-animation uisplitviewcontroller ios

我申请了闪烁的动画到contentViewtableViewcell在splitviewController第一的viewController表.我的问题是,当我使用splitViewController的presentsWithGesture属性隐藏FirstViewcontroller时动画停止

我有子类的UITableViewCell我添加动画,同时设置一个属性,我加入了动画到contentViewcell像下面

-(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"];
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道是否ViewController的行为是在隐藏时在其视图层次结构中停止核心动画,还是在我的代码中遗漏了某些内容.所以帮助我同行

Jos*_*hen 5

是的,layer一旦隐藏了视图控制器,动画就会从视图中删除.奇怪的是,有时动画可以持续,即使view.layer.animationKeys.count == 0,但通常不会.

最好的办法是启动动画中-viewWillAppear:还是-viewDidAppear:......为@vignesh_kumar,也许是通过类似的方法:

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

@doNotCheckMyBlog,在这里你可以调用启动headerView动画的方法.

除此之外,我猜测如果你背景应用程序然后恢复它,动画也会停止.

您还需要-startAnimations在应用程序恢复时调用该方法.例如,您的应用程序代理可以发送出NSNotification在其-applicationDidBecomeActive:-applicationWillEnterForeground:方法.您MasterViewController可以观察此通知并-startAnimations在收到通知时致电.

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