【问题标题】:How to disable selection animations in a UICollectionView?如何在 UICollectionView 中禁用选择动画?
【发布时间】:2015-10-14 18:08:27
【问题描述】:

我目前有一个自定义 UICollectionViewCell,我在其中覆盖 setSelected:。头文件状态:The collection view may call the setters inside an animation block. 选择正在动画,但我不想要动画。

我尝试通过以下方式禁用动画:

[UIView performWithoutAnimation:^{
    self.label.font = font;
}];

还有+[UIView setAnimationsEnabled:],但动画仍然存在。

我的猜测是字体更改本身不是动画的,但它会触发布局传递,因为标签现在更大了。有没有办法禁用单元格的布局?

【问题讨论】:

    标签: ios animation uicollectionview uicollectionviewcell selected


    【解决方案1】:

    设置字体会触发布局。强制立即布局传递,防止在选择/取消选择单元格时出现任何可见动画。这是我的自定义单元格setSelected: 方法:

     - (void) setSelected:(BOOL)selected;
     {
       [super setSelected:selected];
       self.label.font = self.selectedFont;
       [self layoutIfNeeded]; // force layout to avoid UICollectionView animation
     }
    

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 2012-11-26
      相关资源
      最近更新 更多