FSPagerView
FSPagerView copied to clipboard
Changing alpha in subclass of FSPagerViewTransformer changes mode from ferrisWheel to linear
Hi,
I am subclassing FSPagerViewTransformer as following:
`
class CarouselPagerViewTransformer: FSPagerViewTransformer {
init() {
super.init(type: FSPagerViewTransformerType.ferrisWheel)
}
override func proposedInteritemSpacing() -> CGFloat {
return 10.0
}
override func applyTransform(to attributes: FSPagerViewLayoutAttributes) {
guard let pagerView = self.pagerView else {
return
}
let position = attributes.position
let scrollDirection = pagerView.scrollDirection
guard scrollDirection == .horizontal else { return }
var zIndex = 0
var transform = CGAffineTransform.identity
switch position {
case -5 ... 5:
let itemSpacing = attributes.bounds.width + self.proposedInteritemSpacing()
let count: CGFloat = 14.0
let circle: CGFloat = .pi * 2.0
let radius = itemSpacing * count / circle
let ty = radius
let theta = circle / count
let rotation = position * theta
transform = transform.translatedBy(x: -position * itemSpacing, y: ty)
transform = transform.rotated(by: rotation)
transform = transform.translatedBy(x: 0, y: -ty)
zIndex = Int((4.0 - abs(position) * 10))
default:
break
}
attributes.alpha = abs(position) > 1.0 ? 0.0 : 1.0 // changed from default
attributes.transform = transform
attributes.zIndex = zIndex
}
}
` However, changing the attributes.alpha from the default to other values (even constant 1) will make the pager view mode to linear instead of ferrisWheel. Could you please help me with this?
fileprivate func applyTransform(to attributes: FSPagerViewLayoutAttributes, with transformer: FSPagerViewTransformer?) {
guard let collectionView = self.collectionView else {
return
}
guard let transformer = transformer else {
return
}
switch self.scrollDirection {
case .horizontal:
let ruler = collectionView.bounds.midX
attributes.position = (attributes.center.x-ruler)/self.itemSpacing
case .vertical:
let ruler = collectionView.bounds.midY
attributes.position = (attributes.center.y-ruler)/self.itemSpacing
}
attributes.zIndex = Int(self.numberOfItems)-Int(attributes.position)
transformer.applyTransform(to: attributes)
}
transformer: FSPagerViewTransformer? transformer.applyTransform(to: attributes) 上面的源码调用方式决定了当前的源码应该无法满足你的上面写法的需求,建议直接用源码引入替代pod的引入,然后直接修改源码。 或者将FSPagerViewTransformer改为面向协议的方式FSPagerViewTransformerProtocol应该可以符合你的写法需求。 当然你需要改造一下FSPagerViewTransformer。