swift - 为什么 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
}
谢谢你的帮助
解决方案
对于任何想知道我们的人car.cliptobounds=true
推荐阅读
- javascript - 如何在 html 模板中从 Django-object 传递 JavaScript 变量?
- vb.net - VB.NET 循环计数每本书的作者
- sql - 在 SQL 中为 INSERT 和 UPDATE 编写触发器
- express - Cloudinary\Error:缺少必需的参数 - 文件 - Express 和 Postman
- c# - 如何在 ASP.NET 中设置默认参数
- python - snakemake 中 {sample} 和 {wildcard.sample} 的区别
- pytorch - pytorch 中是否有元素映射功能?
- algorithm - 我如何计算使用 2 x 1 瓷砖平铺 n*n 板的方法数量
- c# - Null Coalessing 未返回正确值
- delphi - 在 Delphi (FMX) 中找不到文件