Rob*_*egg 16 objective-c uicollectionviewlayout ios7
我在iOS7中忙于UICollectionView.
我正在两个不同的布局之间更改我的集合视图的布局.这是UICollectionViewFlowLayout的子类.
这是我点击按钮时更改视图的方式:
-(void)changeViewLayoutButtonPressed
{
self.changeLayout = !self.changeLayout;
if (self.changeLayout){
[self.tableViewLayout invalidateLayout];
[self.tradeFeedCollectionView setCollectionViewLayout:self.grideLayout animated:YES];
}
else {
[self.grideLayout invalidateLayout];
[self.tradeFeedCollectionView setCollectionViewLayout:self.tableViewLayout animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
此方法按预期工作,并使用漂亮的动画更改视图.但是在控制台中我收到这些消息:
快照未呈现的视图会导致空快照.确保在屏幕更新后快照或快照之前至少渲染了一次视图.
关于是什么导致这个的任何想法?
只是扩展上面的评论......
我收到警告的奇怪之处在于我的cv有三个可能的dataSources.所有这些数据基本上与以下数据相同:集合1,集合2,集合1和2.
当我刚看到Collection 1或Collection 2时,我没有收到任何警告.只有当我看到这两个组合时,我才收到警告.关于这一点的奇怪之处在于,没有什么可以展示一切.集合1和集合2从"整体"中提取,因此在那里增加一步.不确定这意味着什么.
无论如何,我不再收到消息.
这是我原来的:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self arrangeCollectionView];
}
- (void)arrangeCollectionView
{
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.cv.collectionViewLayout;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
flowLayout.sectionInset = UIEdgeInsetsMake(16, 16, 16, 16);
flowLayout.minimumInteritemSpacing = 16;
flowLayout.minimumLineSpacing = 16;
}
else
{
flowLayout.sectionInset = UIEdgeInsetsMake(26, 26, 26, 26);
flowLayout.minimumInteritemSpacing = 26;
flowLayout.minimumLineSpacing = 26;
}
self.cv.collectionViewLayout = flowLayout;
}
Run Code Online (Sandbox Code Playgroud)
这给了我关于旋转到Landscape的信息,但没有转到Portrait时.
这两个更改都导致没有更多消息:
1.运用
didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
打电话arrangeCollectionView而不是
willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
解决了警告问题,但过渡有点粗糙.
2.摆脱的明确更改UICollectionViewFlowLayout和使用DelegateFlowLayout方法,并呼吁reloadData来自willAnimateRotation...:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.cv reloadData];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize retval = CGSizeMake(172, 256);
return retval;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? UIEdgeInsetsMake(16 + 66, 16, 16, 16) : UIEdgeInsetsMake(26 + 66, 26, 26, 26);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? 16 : 28;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? 16 : 28;
}
Run Code Online (Sandbox Code Playgroud)
这对我来说效果最好.没有更多的消息和从一个布局到另一个布局的相当平滑的过渡.
希望这可以帮助您追踪它.我猜截图拍摄后,流布局失效期间呈现给用户,并同时在同一时间布局已被重新设置此快照正在采取willRotate......也许反正.仍然不确定为什么我的2个数据子集始终为零消息,并且始终始终为完整集合发送消息.
祝你好运,希望它有所帮助.
小智 6
这个问题也发生在我身上.我通过调用:UIScreen.mainScreen().snapshotViewAfterScreenUpdates(true)在setCollectionViewLayout方法之前解决它.我也不知道为什么.我希望它可以提供帮助.
我有这个问题,因为我仅在横向模式下才使用UICollectionView,并且第一次旋转至横向(也是第一次)时,会得到许多有关快照的日志条目。我意识到日志条目的数量与单元格+标头视图的数量相匹配,因此我将此代码添加到了自定义单元格类和标头视图类中,日志条目消失了:
- (UIView*)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates
{
UIGraphicsBeginImageContext(self.bounds.size);
[self drawRect:self.bounds];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView* aView = [[UIImageView alloc] initWithFrame:self.bounds];
[aView setImage:viewImage];
return aView;
}
Run Code Online (Sandbox Code Playgroud)
我需要做更多的测试,看看这是否是正确的方法,但是目前它正在工作。
- (UIView *)snapshotViewAfterScreenUpdates:当尚未呈现的视图上的方法时,它会生成此控制台警告。
要么您在某处调用此方法,要么更有可能的是,正在setCollectionViewLayout: animated:使用此方法,并且集合视图在使用时尚未呈现。
我的建议是不要调用- (void)invalidateLayout集合视图并看看会发生什么。
| 归档时间: |
|
| 查看次数: |
5870 次 |
| 最近记录: |