我正在尝试为 Collection View 单元格设置动画,这是我目前的代码
- (void)collectionView:(UICollectionView *)collectionView didUpdateFocusInContext:(UICollectionViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator{
UICollectionViewCell *nextFocusedCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCell" forIndexPath:context.nextFocusedIndexPath];
UICollectionViewCell *previousFocusedCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCell" forIndexPath:context.previouslyFocusedIndexPath];
if (context.nextFocusedView) {
[coordinator addCoordinatedAnimations:^{
[nextFocusedCell setFrame: CGRectMake(3, 14, 300, 300)];
} completion:^{
// completion
}];
} else if (context.previouslyFocusedView) {
[coordinator addCoordinatedAnimations:^{
[previousFocusedCell setFrame: CGRectMake(3, 14, 100, 100)];
} completion:^{
// completion
}];
}
但是我的代码不工作。我已经阅读了文档,它说要实现类似的东西 if (self == contextFocusedView)......但是它有一个警告说不兼容的指针 View Controller 到 UIView。有人可以告诉我我的代码有什么问题以及如何修复它吗?谢谢!!
最佳答案
dequeueReusableCellWithReuseIdentifier:
不会返回当前 View ,而是返回一个新 View 。
尝试使用 cellForItemAtIndexPath:
但为什么不使用:
if (context.nextFocusedView) {
[coordinator addCoordinatedAnimations:^{
context.nextFocusedView.transform = CGAffineTransformMakeScale(1.1, 1.1);
} completion:nil];
}
if (context.previouslyFocusedView) {
[coordinator addCoordinatedAnimations:^{
context.previouslyFocusedView.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:nil];
}
关于ios - Collection View 单元动画 tvOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33202335/