我有一个UICollectionViewController
和一个UIImageView
作为IBOutlet
在每个单元格内。我为图像视图设置了imageView.adjustsImageWhenAncestorFocused = true
,并且当相关单元聚焦时,图像视图变得太大。只是想知道是否有任何方法来控制图像视图的动画行为。我知道我可以覆盖didUpdateFocusInContext(_:withAnimationCoordinator:)
,但无法找到如何处理悬停事件。
任何帮助,将不胜感激。如何在UICollectionViewCell中关注UIImageView的默认动画行为?
1
A
回答
1
因此,使用函数来更新您的细胞,当焦点在当前选定的单元格。
先为图像视图禁用adjustsImageWhenAncestorFocused
属性,然后根据您的愿望更改imageview的大小。
定义两种不同的尺寸,并将其用于聚焦细胞和细胞的其余部分。
CGSize originalCellSize = CGSizeMake(225, 354);
CGSize focusCellSize = CGSizeMake(240, 380);
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
[coordinator addCoordinatedAnimations:^{
if (self.focused) {
self.imageView.frame.size = focusCellSize;
} else {
self.imageView.frame.size = originalCellSize;
}
} completion:nil];
}
使用animatewithDuration:
以提供更好的动画风格,当你更改单元格大小或使用字母或阴影的更完美的外观为ImageView的效果。
0
也许更好的解决方案是用单元格(或单元格的contentView)上的CGAffineTransform来处理这个问题。这样你就不需要改变视图框架(你也可以在self.imageView.transform上进行转换,如果这更适合你的话)。
#pragma mark - UIFocusEnvironment
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
if (self.focused) {
[coordinator addCoordinatedAnimations:^{
self.transform = CGAffineTransformMakeScale(1.1f, 1.1f);
} completion:nil];
} else {
[coordinator addCoordinatedAnimations:^ {
self.transform = CGAffineTransformMakeScale(1.f, 1.f);
} completion:nil];
}
}
相关问题
- 1. 如何在默认页面动画
- 2. 关于UIImageView常量动画
- 3. “默认”动画后
- 4. 如何动画UIImageView背景
- 5. UICollectionViewCell翻转动画
- 6. UICollectionViewCell扩大动画
- 7. 的UIImageView动画
- 8. UIImageView不动画
- 9. 动画UIImageView iPhone
- 10. 移动uiimageview动画
- 11. Android - 替换默认的活动动画
- 12. 如何获取动画UIImageView的坐标
- 13. Swift 3/4如何动画UIImageView的contentMode
- 14. UICollectionViewCell动画有了协议
- 15. 如何在android中为所有动画设置默认插补器?
- 16. UIImageView不会加载UICollectionViewCell中的图像
- 17. UIImageView上的摆动动画
- 18. 如何更改ThickBox的默认行为?
- 19. UIImageView的动画仅运行一次
- 20. 动画到UIImageView在objective-c
- 21. UIImageView动画的动画帧图像
- 22. 为什么新的UIImageView无法动画?
- 23. 更改默认的Ubuntu画中画pip2.7
- 24. 我如何默认/关注jQuery的按钮
- 25. 动画UIImage或UIImageView?
- 26. UIImageView动画缓慢
- 27. UIImageview动画问题?
- 28. UIImageView闪烁动画
- 29. 动画一个UIImageView
- 30. 动画UIImageView色调