【问题标题】:Why are iCarousel items scrolling beyond boundaries?为什么 iCarousel 项目滚动超出边界?
【发布时间】:2021-08-19 20:42:35
【问题描述】:

大家好,我正在使用 iCarousel,一切正常,只是放置的项目超出了轮播的边界如何确保超出这些边界的项目被隐藏?

轮播变量:

lazy var car:iCarousel = {
        let view = iCarousel()
        view.frame = CGRect(x:0, y:Int(CGFloat(Double(Int(Float(bounds.size.height*0.05))) + globW  )) , width: Int(Float(bounds.size.width)*0.85), height: Int(Float(bounds.size.height)*0.75))
        view.type = .coverFlow
        view.isVertical = true
        view.bounces = true
        
//        view.backgroundColor = .red
        return view
    }() 

轮播功能:

 func numberOfItems(in carousel: iCarousel) -> Int {
       return currentField.count
    }

    func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
        let v = UIView(frame: CGRect(x: 0, y:0, width: car.bounds.width, height: car.bounds.height*0.5))
        
            if currentField[index].type == "A"{
                let cont=UITextField()
                let img=UIImageView()
                img.frame=CGRect(x: Double(Int(Float(bounds.size.width*0.05))), y: Double(v.bounds.height)*0.5, width:Double(bounds.size.width)*0.1, height: Double(bounds.size.width)*0.1)
           
                img.image=UIImage(named: currentField[index].path)?.resized(to: CGSize(width: CGFloat(bounds.size.width*0.1), height: CGFloat(bounds.size.width*0.1)))
              

                cont.textColor = .white
                cont.attributedPlaceholder = NSAttributedString(string: currentField[index].placeholder, attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray])
                cont.setBottomBorder(color:UIColor.gray.cgColor)
                cont.frame = CGRect(x: CGFloat(Int(Float(car.bounds.width*0.4))), y: v.bounds.height*0.5 /*CGFloat(Int(Float(car.frame.height*0.5)))-25*/, width: CGFloat(Int(Float(bounds.size.width)))-CGFloat(Int(Float(bounds.size.width*0.2))), height: 50)
            cont.backgroundColor = .clear
                v.addSubview(img)
           v.addSubview(cont)
                cont.addTarget(self, action: #selector(editTypeA(_:)), for: UIControl.Event.editingChanged)

            }
   
        
           return v
    }

感谢您的帮助

【问题讨论】:

    标签: swift icarousel


    【解决方案1】:

    尝试采用“委托”协议并实现这个确切的方法:

        func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
            switch option {
            case .visibleItems:
                return 3
            default:
                return value
            }
        }
    

    【讨论】:

      【解决方案2】:

      对于任何想知道我们的人car.cliptobounds=true

      【讨论】:

        猜你喜欢
        • 2017-02-19
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-02
        • 1970-01-01
        相关资源
        最近更新 更多