【发布时间】:2016-01-07 15:58:56
【问题描述】:
我正在构建一个 tvos 应用程序。我有一个UITableView,它有大约 25-30 个部分。每个部分只有一行,在每一行中我只有一个水平的UICollectionView,它只有一个部分但有很多行。在@ 987654325中的每一行中,我有一个图像视图,我在选择UICollectionViewCell时缩放。
我知道我可以用adjustsImageWhenAncestorFocused 做到这一点,但我的情况稍微复杂一些。实际上我在UICollectionViewCell 中有两个imageViews 我在较大的imageView 上使用adjustsImageWhenAncestorFocused 但如果在较小的imageView 上使用它,那么我看起来会很糟糕。所以这就是为什么我必须在较小的 imageView 上使用缩放。
我面临的问题是,当某个地方 UICollectionViewCell indexPath 搞砸了,这导致当我转到一些新的 UICollectionViewCell 时,较小的图像已经被缩放,我变得越来越大,有些单元格真的非常由于过度缩放而非常大
这是故事板设置的图像
这是我的代码,任何帮助都会很棒。
func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
guard let nextIndexPath = context.nextFocusedIndexPath else{
return
}
guard let nextFocusedCell = collectionView.cellForItemAtIndexPath(nextIndexPath) as? MyCollectionViewCell else{
return
}
if nextFocusedCell.teacherImageView != nil {
coordinator.addCoordinatedAnimations({ () -> Void in
let focusedTransform = CGAffineTransformScale(nextFocusedCell.teacherImageView.transform, 1.4, 1.4)
nextFocusedCell.teacherImageView.transform = focusedTransform
},
completion: nil
)
}
guard let previousIndexPath = context.previouslyFocusedIndexPath else {
return
}
guard let prevFocusedCell = collectionView.cellForItemAtIndexPath(previousIndexPath) as? MyCollectionViewCell else{
return
}
if prevFocusedCell.teacherImageView != nil {
coordinator.addCoordinatedAnimations({ () -> Void in
let focusedTransform = CGAffineTransformScale(prevFocusedCell.teacherImageView.transform, 1/1.4, 1/1.4)
prevFocusedCell.teacherImageView.transform = focusedTransform
},
completion: nil
)
}
}
【问题讨论】:
标签: ios uiimageview uicollectionview tvos nsindexpath