首页 > 解决方案 > 为什么 iCarousel 项目滚动超出边界?

问题描述

嘿,我正在使用 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
    }

谢谢你的帮助

标签: swifticarousel

解决方案


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


推荐阅读