【问题标题】:How Do I Properly Use iCarouselOptions with iOS iCarousel?如何在 iOS iCarousel 中正确使用 iCarouselOptions?
【发布时间】:2019-04-01 08:08:26
【问题描述】:

我正在使用 Swift 创建一个 iOS 应用程序,并且正在使用来自 GitHub 的 iCarousel(通过 cocoapods 安装),但我不确定我做错了什么,但我似乎无法获得我设置的 iCarouselOptions效果...

我想要做的只是改变我的轮播中 UIViews 的间距(它们太靠近并且重叠,我不想要)。

这是我的代码:

    import UIKit
    import iCarousel

    class MiniGamesViewController: UIViewController, iCarouselDelegate, iCarouselDataSource {

        //Objects
        @IBOutlet weak var leaveMinigamesButton: UIButton!

        //Variables
        var carouselHeight : CGFloat!
        var selectionBallSize : CGFloat!

        override func viewDidLoad() {
            super.viewDidLoad()

            leaveMinigamesButton.layer.zPosition = 3
            carouselHeight = self.view.frame.size.height - 200
            selectionBallSize = self.view.frame.size.width * 0.65

            let carousel = iCarousel(frame: CGRect(
                x: 0,
                y: 100,
                width: self.view.frame.size.width,
                height: carouselHeight))

            carousel.perspective = -0.005
            carousel.centerItemWhenSelected = true
            carousel.decelerationRate = 0.9
            carousel.viewpointOffset = CGSize(width: 0, height: 0) //-selectionBallSize * 1.2

            carousel.dataSource = self
            carousel.type = .rotary
            view.addSubview(carousel)
        }

        override func viewDidAppear(_ animated: Bool) {
            setNeedsStatusBarAppearanceUpdate()
        }

        //This is how many items there will be in my rotary iCarousel
        func numberOfItems(in carousel: iCarousel) -> Int {
            return 6
        }

        //This defines each item or 'cell' in the iCarousel
        func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
            let imageView: UIImageView
            if view != nil {
                imageView = view as! UIImageView
            } else {
                imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: selectionBallSize, height: selectionBallSize))
            }
            imageView.image = UIImage(named: "orbCyan")
            return imageView
        }

        func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
            switch (option) {
            case .spacing: return value * 2
            case .radius: return 200
            case .fadeMinAlpha: return 0.5
            default: return value
            }
        }
}

特别是我的代码的最底部是自定义的地方 应该生效,但是当我运行该应用程序时它似乎没有进行任何更改。目前,我只关心尝试将轮播中的 UIView 间隔得更远。

我是否将 iCarouselOptions 函数放在正确的位置?它甚至被“称为”吗?

感谢您的帮助!

【问题讨论】:

    标签: ios swift icarousel


    【解决方案1】:

    你不知道吗,我一发布这个问题,我就发现了问题哈哈(经过一天的尝试)。原来我错过了简单的一行:

    carousel.delegate = self
    

    下面:

    carousel.dataSource = self
    

    这完全成功了,现在它可以工作了,哈哈。我需要一双全新的眼睛:P

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      相关资源
      最近更新 更多