ios - Collection View 单元动画 tvOS

标签 ios objective-c uicollectionview uicollectionviewcell tvos

我正在尝试为 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/

相关文章:

ios - 尝试使用 swift 将 XML 从 URL 解析为 PickerView

ios - 来自 UICollectionViewCell 的 UIAlertController

php - 将数据从 IOS 应用程序发布到 PHP Web 服务(托管 GODADDY)

objective-c - 在哪里可以找到 Objective-C 2.0 的 EBNF 语法

ios - 在 iOS 中使用 NSFileManager 写入文件

ios - UICollectionView:最后一行的项目之间不需要的空间

ios - UICollectionView 在特定部分开始

ios - 如何使此 UILabel 将电子邮件地址移动到下一行?

ios - 多个 TableViewController 和 Segues

ios - 在 swift 中渲染 UIImageView 时质量松散