在tvOS

时间:2017-04-04 15:35:11

标签: objective-c uicollectionview focus uicollectionviewcell tvos

所以我有一个UICollectionView,我已经做到这一点,当焦点变为新单元格时,单元格中的图像会扩展。出于某种原因,尽管UICollectionView加载第一个单元格时大于其他单元格(请参见下面的屏幕截图)。我怎么能阻止它这样做?

enter image description here

我在焦点上更改图像的代码是:

- (void)collectionView:(UICollectionView *)collectionView didUpdateFocusInContext:(UICollectionViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {

    NSIndexPath *previousIndexPath = context.previouslyFocusedIndexPath;
    NSIndexPath *indexPath = context.nextFocusedIndexPath;

    TrophyCollectionViewCell *previousCell = (TrophyCollectionViewCell *)[collectionView cellForItemAtIndexPath:previousIndexPath];
    TrophyCollectionViewCell *cell = (TrophyCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];

    [UIView animateWithDuration:0.3 animations:^{

        if (previousCell.trophyImageView != nil) {
            previousCell.trophyImageView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
        }

        if (cell.trophyImageView != nil) {
            cell.trophyImageView.transform = CGAffineTransformMakeScale(1.2f, 1.2f);
        }

        if (previousCell.resetImageView != nil) {
            previousCell.resetImageView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
        }

        if (cell.resetImageView != nil) {
            cell.resetImageView.transform = CGAffineTransformMakeScale(1.2f, 1.2f);
        }

    }];

}

除此之外,我没有其他影响细胞大小的代码。

2 个答案:

答案 0 :(得分:0)

我设法通过在CGAffineTransformMakeScale(1.0f, 1.0f);方法中为先前关注的和下一个关注的单元格设置didUpdateFocusInContext来解决此问题。

答案 1 :(得分:0)

焦点管理器从屏幕的左上角开始查找第一个可聚焦元素,以便更大的元素可能是获得焦点的元素。

它可能更大,因为当Ancestor Focused设置为true时,属性会调整Image。

https://developer.apple.com/reference/uikit/uiimageview/1627692-adjustsimagewhenancestorfocused