美文网首页Objective-ciOS
iOS开发过程中遇到的问题(持续更新)

iOS开发过程中遇到的问题(持续更新)

作者: 狂奔的大蜗牛 | 来源:发表于2017-05-05 17:45 被阅读819次

    记录自身在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];
    }
    

    相关文章

      网友评论

        本文标题:iOS开发过程中遇到的问题(持续更新)

        本文链接:https://www.haomeiwen.com/subject/khjstxtx.html