旋转时的 UICollectionViewCell alpha 值 [英] UICollectionViewCell alpha value on Rotate

查看:26
本文介绍了旋转时的 UICollectionViewCell alpha 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义 UICollectionViewCellUICollectionView.我将 UICollectionViewCell 中的 alpha 属性设置为 0.0f 以用于特定任务,所有这些都按预期工作.但是,当我将视图旋转到横向时,单元格的 alpha 将自身重置为 1.0.

I have a UICollectionView with a custom UICollectionViewCell. I set the alpha property in the UICollectionViewCell to 0.0f for a speific task which all works as expected. However, when I rotate the view to landscape the cell's alpha resets itself to 1.0.

我已经解决了这个问题,集合视图保存了选定单元格和删除单元格等的状态,但不保存单元格的 alpha 值.

I've played around with this and the collection view holds the state of selected cells and removed cells etc. but not the alpha value of the cell.

我尝试在 didRotateFromInterfaceOrientation: 上重新设置更改单元格的 alpha 值,它确实这样做了,但是一旦调用完成,将其更改回 1.0.

I have tried to re-set the alpha values of the changed cells on didRotateFromInterfaceOrientation:, which it does but then changes it back to 1.0 once that call has completed.

我想弄清楚 UICollectionViewCell 的 alpha 值在旋转后在哪里重置.

I'm trying to figure out where the alpha value of the UICollectionViewCell is resetting itself after it rotates.

如果我运行下面的代码,我会为单元格取回所需的 alpha 值,但是在此之后的某个时刻它们都变回 1.0:

If I run the below code I get the desired alpha values back for the cells, however at some point after this they all change back to 1.0:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    //array containing IndexPaths for cells with 0.0f alpha value
    for (NSIndexPath *path in self.selectedlettersArray) {
        LetterCellView* lsv = (LetterCellView*) [self.collectionView     cellForItemAtIndexPath:path];
        lsv.alpha = 0.0f; 
    }

    for (LetterCellView *lsv in self.collectionView.visibleCells) {

        NSLog(@"After Cell Alpha is : %f", lsv.alpha);

    } 
}

有什么想法吗?

推荐答案

在集合视图中,alpha - 连同其他属性 - 不能通过通常的视图属性可靠地管理,至少这不是故意的.

In collection views the alpha - along with other properties - is not reliably managed via the usual view properties, at least this is not intended.

相反,您应该使用由 UICollectionReusableView 类通过 applyLayoutAttributes 管理的 UICollectionViewLayoutAttributes 对象的 alpha 属性:.

Instead, you should use the alpha property of UICollectionViewLayoutAttributes object that is managed by the UICollectionReusableView class via applyLayoutAttributes:.

阅读
UICollectionReusableView 类参考
UICollectionViewLayoutAttributes 类参考

这篇关于旋转时的 UICollectionViewCell alpha 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆