gpt4 book ai didi

ios - 如何实现像 iCarousel Rotary 类型、Objective-C 这样的 UI?

转载 作者:行者123 更新时间:2023-12-01 18:06:03 25 4
gpt4 key购买 nike

我想实现这种类型的 UI(水平滚动)。

enter image description here

我知道它的“iCarousel”类型,Type = iCarouselTypeRotary。我尝试使用这个库,但我得到了这种类型的 UI。我无法完全自定义:

enter image description here
如果有人知道如何以 native 方式或其他任何库来执行此 UI,请告诉我。任何输入将不胜感激。

最佳答案

iCarousel 库提供 iCarouselTypeCustom 类型。

以下是一个自定义示例。

override func awakeFromNib() {
super.awakeFromNib()
for i in 0 ... 6 {
items.append(i)
}
}

override func viewDidLoad() {
super.viewDidLoad()
carousel.type = .custom
}

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


func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
var label: UILabel
var itemView: UIImageView

if let view = view as? UIImageView {
itemView = view
label = itemView.viewWithTag(1) as! UILabel
} else {

itemView = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))

itemView.image = UIImage(named: "page.png")
itemView.layer.cornerRadius = 5

itemView.contentMode = .center

label = UILabel(frame: itemView.bounds)
label.backgroundColor = .clear
label.textAlignment = .center
label.font = label.font.withSize(50)
label.tag = 1
itemView.addSubview(label)
}

label.text = "\(items[index])"

return itemView
}

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {

switch option {
case .visibleItems:
let elemento:Int = self.carousel.currentItemIndex as Int
print(elemento)
if elemento == 0 {
return 2;
}else if elemento == items.count-1 {
return 2;

}else {
return 3;
}

default:
return value
}
}

func carousel(_ carousel: iCarousel, itemTransformForOffset offset: CGFloat, baseTransform transform: CATransform3D) -> CATransform3D {


let offsetFactor:CGFloat = self.carousel(carousel, valueFor: .spacing, withDefault: 1.25) * carousel.itemWidth

let zFactor: CGFloat = 400.0
let normalFactor: CGFloat = 0
let shrinkFactor: CGFloat = 100.0

let f: CGFloat = sqrt(offset * offset + 1)-1

var trans = transform

trans = CATransform3DTranslate(trans, offset * offsetFactor, f * normalFactor, f * (-zFactor))
trans = CATransform3DScale(trans, 1 / (f / shrinkFactor + 1.0), 1 / (f / shrinkFactor + 1.0), 1.0 )


return trans
}

func carousel(_ carousel: iCarousel, shouldSelectItemAt index: Int) -> Bool {
return true
}

关于ios - 如何实现像 iCarousel Rotary 类型、Objective-C 这样的 UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44159560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com