UICollectionViewCell旋转的alpha值
我有一个自定义UICollectionViewCell
。 我将UICollectionViewCell
的alpha
属性设置为0.0f
,以满足所有按预期工作的特定任务。 但是,当我旋转视图横向单元格的alpha
重置为1.0
。
我玩过这个,集合视图保存选定单元格的状态,并删除单元格等,但不是单元格的alpha值。
我试图在didRotateFromInterfaceOrientation:
上重新设置更改单元格的alpha值,但是一旦调用完成,它就会将其更改回1.0
。
我试图找出UICollectionViewCell
的alpha值在旋转后重置自己的位置。
如果我运行下面的代码,我得到所需的alpha值为单元格,但在此之后的某些点,他们都改回到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和其他属性并不能通过常见的视图属性进行可靠的pipe理,至less这不是可行的。
相反,您应该使用UICollectionViewLayoutAttributes
对象的alpha
属性, UICollectionViewLayoutAttributes
对象由UICollectionReusableView
类通过applyLayoutAttributes:
。
在这里阅读
UICollectionReusableView类参考和
UICollectionViewLayoutAttributes类参考
基于Mundi的build议UICollectionViewCell alpha属性是不可靠的托pipe,我最终添加一个属性到我的自定义UICollectionViewCell设置为可见或隐藏。 我只是把单元格的内容(在我的例子中是一个标签)设置为0或1。
这现在坚持当我旋转设备,虽然它似乎有点解决方法。