iOS開發過程中遇到的問題(持續更新)

記錄自身在iOS開發過程中遇到的問題,方便以后經常查看,同時也給大家做個參考。

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.

出現這個問題證明是UICollectionView的itemSize寬度設置錯了,同樣,高度設置錯了也會出現類似的提示,在網上搜了一下,有如下幾種解決辦法:

1)、不讓collectionview的內容自動調整

self.automaticallyAdjustsScrollViewInsets = NO;

原因:當automaticallyAdjustsScrollViewInsets為YES時,它會找view里的scrollView,并設置scrollView的contentInset為{64, 0, 0, 0}。如果你不想讓scrollView的內容自動調整,將這個屬性設為NO(默認值YES)。

2)、手動調整itemSize的大小

KanbanCollectionViewHorizontalLayout *horizontalLayout = [[KanbanCollectionViewHorizontalLayout alloc] init];
[horizontalLayout setItemSize:CGSizeMake((SCREEN_WIDTH)/4, 55)]; // 這里設置item的大小是55

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 0, 10, 0); // 上下間距是10
}

我設置的collectionview的高度是70,但是item的大小和上下間距加起來是75,超過了設置的高度,所以會報上面的錯誤,后來把上下間距改成5就解決問題了。

2、單張圖片無限旋轉效果

// 開啟
- (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"];
}
// 關閉
- (void)refreshButtonStopAnimation:(UIButton *)button
{
    [button.imageView.layer removeAllAnimations];
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容