gpt4 book ai didi

ios - 当 split viewcontroller 的 Master 隐藏时核心动画停止(在纵向模式下)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:29:50 25 4
gpt4 key购买 nike

我将闪烁动画应用于 tableViewcellcontentView,用于 splitviewController 的 First viewController 中的表格。我的问题是,当我使用 splitViewController 的 presentsWithGesture 属性隐藏 FirstViewcontroller

时,动画停止

我将 UItableViewCell 子类化,并在设置属性时添加动画,并且我将动画添加到 cellcontentView 中,如下所示

-(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 的行为是在隐藏时停止其 View 层次结构中的核心动画,还是我在代码中遗漏了某些内容。所以帮助我的同行

最佳答案

是的,一旦 View Controller 被隐藏,动画就会从 View 的 layer 中移除。奇怪的是,有时即使 view.layer.animationKeys.count == 0 动画也可以持续,但通常不会。

你最好的选择是在 -viewWillAppear:-viewDidAppear: 中启动动画...对于@vignesh_kumar,也许通过这样的方法:

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

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

除此之外,我猜如果您将应用设置为后台然后继续运行,动画也会停止。

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

如果您不需要在动画中返回到完全相同的状态,那么这应该不是什么大问题。如果您需要在动画中返回到与应用进入后台时相同的状态,那么您还需要保存状态,然后在重新启动动画时设置初始状态。

关于ios - 当 split viewcontroller 的 Master 隐藏时核心动画停止(在纵向模式下)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18650679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com