記錄自身在iOS開(kāi)發(fā)過(guò)程中遇到的問(wèn)題村刨,方便以后經(jīng)常查看巩趁,同時(shí)也給大家做個(gè)參考宗弯。
1脯燃、collectionview打印異常log
The behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <KanbanCollectionViewHorizontalLayout: 0x7fa39960c8e0>, and it is attached to <UICollectionView: 0x7fa39a8ba000; frame = (0 0; 375 70); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x60800064fba0>; layer = <CALayer: 0x608000230800>; contentOffset: {0, 0}; contentSize: {187.5, 70}> collection view layout: <KanbanCollectionViewHorizontalLayout: 0x7fa39960c8e0>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
出現(xiàn)這個(gè)問(wèn)題證明是UICollectionView的itemSize寬度設(shè)置錯(cuò)了,同樣蒙保,高度設(shè)置錯(cuò)了也會(huì)出現(xiàn)類似的提示辕棚,在網(wǎng)上搜了一下,有如下幾種解決辦法:
1)邓厕、不讓collectionview的內(nèi)容自動(dòng)調(diào)整
self.automaticallyAdjustsScrollViewInsets = NO;
原因:當(dāng)automaticallyAdjustsScrollViewInsets為YES時(shí)逝嚎,它會(huì)找view里的scrollView,并設(shè)置scrollView的contentInset為{64, 0, 0, 0}详恼。如果你不想讓scrollView的內(nèi)容自動(dòng)調(diào)整补君,將這個(gè)屬性設(shè)為NO(默認(rèn)值YES)。
2)昧互、手動(dòng)調(diào)整itemSize的大小
KanbanCollectionViewHorizontalLayout *horizontalLayout = [[KanbanCollectionViewHorizontalLayout alloc] init];
[horizontalLayout setItemSize:CGSizeMake((SCREEN_WIDTH)/4, 55)]; // 這里設(shè)置item的大小是55
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(10, 0, 10, 0); // 上下間距是10
}
我設(shè)置的collectionview的高度是70挽铁,但是item的大小和上下間距加起來(lái)是75她紫,超過(guò)了設(shè)置的高度,所以會(huì)報(bào)上面的錯(cuò)誤屿储,后來(lái)把上下間距改成5就解決問(wèn)題了贿讹。
2、單張圖片無(wú)限旋轉(zhuǎn)效果
// 開(kāi)啟
- (void)refreshButtonStartAnimation:(UIButton *)button
{
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
rotationAnimation.duration = 0.8;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = ULLONG_MAX;
[button.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
// 關(guān)閉
- (void)refreshButtonStopAnimation:(UIButton *)button
{
[button.imageView.layer removeAllAnimations];
}