Raf*_*fAl 6 apple-tv uicollectionview tvos
有没有办法禁用自动滚动UICollectionView时单元格聚焦?我想在聚焦时手动调整单元格的内容偏移量.
我不想更新内容偏移量:
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context
withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
[coordinator addCoordinatedAnimations:^
{
[UIView animateWithDuration:[UIView inheritedAnimationDuration]
animations:^
{
// Move next focused cell.
if ([context.nextFocusedView isKindOfClass:[YBZEventCollectionViewCell class]])
{
UICollectionViewCell *cell = (UICollectionViewCell *)context.nextFocusedView;
CGPoint offset = CGPointMake(CGRectGetMinX(cell.frame), 0.0f);
[_collectionView setContentOffset:offset];
}
}];
} completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,但由于焦点引擎也移动我的单元格(滚动它)我最终得到的动画不顺畅,在它的末尾有一个"踢".
Jer*_*ker -1
我不知道“自动滚动”是什么意思,但要更改集合视图单元格,您可以在自定义单元格类中使用didUpdateFocusInContext 。
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
coordinator.addCoordinatedAnimations({ [unowned self] in
if self.focused {
self.titleTopConstraint.constant = 27
self.titleLabel.textColor = UIColor.whiteColor()
} else {
self.titleTopConstraint.constant = 5
self.titleLabel.textColor = UIColor(red: 100 / 255, green: 100 / 255, blue: 100 / 255, alpha: 1)
}
self.layoutIfNeeded()
}, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您没有自定义单元格,请使用UICollectionViewDelegate 中的didUpdateFocusInContext 。
func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
coordinator.addCoordinatedAnimations({ () -> Void in
if let indexPath = context.nextFocusedIndexPath, let cell = collectionView.cellForItemAtIndexPath(indexPath) {
// the cell that is going to be focused
}
if let indexPath = context.previouslyFocusedIndexPath, let cell = collectionView.cellForItemAtIndexPath(indexPath) {
// the cell that is going to be unfocused
}
}, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2402 次 |
| 最近记录: |