【发布时间】: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
}
感谢您的帮助
【问题讨论】: