iCarousel间距不平滑

时间:2016-09-27 19:40:22

标签: ios swift image spacing icarousel

我正在尝试制作一个上传图片'系统,我试图调整每个图像之间的空间。然而,它没有按计划进行,因为当旋转木马停止移动时,由于重叠,图像总是必须到达前面。我怎样才能阻止这种重叠?谢谢!

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    if option == .visibleItems {
        return CGFloat(images.count)
    } else if option == .spacing {
        return value * 0.87
    } else if option == .showBackfaces {
        return 0
    }
    return value
}

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {

    let imageView = UIImageView(frame: CGRect(x: getWidths(upTo: index) , y: 0, width: widths[index], height: 200))
    imageView.image = images[index]
    imageView.layer.borderColor = UIColor.black.cgColor
    imageView.contentMode = .scaleAspectFit
    imageView.frame = CGRect(x: getWidths(upTo: index) , y: 0, width: widths[index], height: 200)
    imageView.layer.borderWidth = 4
    return imageView
}

func getWidths(upTo index: Int) -> CGFloat {
    var width = CGFloat()

    for i in 0..<index {
        width += widths[i]
    }

    return width

}

结果如下:

https://1drv.ms/v/s!AiYSVEFiXE12g_gNyVufJ1LqZMcZtw

1 个答案:

答案 0 :(得分:0)

旋转木马的类型是什么,如果您的类型是自定义的,则应覆盖该功能 - (CATransform3D)轮播:(RPiCarousel *)carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform

在此功能中,您可以使用
返回CATransform3DTranslate(transform,offset * self.taskView.itemWidth * offset,0.0,0.0); 这解决了我的问题