Make transformer subclassing friendly.
This commit is contained in:
parent
c2b6415fc9
commit
024eff483d
|
|
@ -7,6 +7,8 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
F954839A1E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */; };
|
||||
F954839B1E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */; };
|
||||
F9580B571E5D995400C5B267 /* FSPageControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B511E5D995400C5B267 /* FSPageControl.swift */; };
|
||||
F9580B581E5D995400C5B267 /* FSPagerCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B521E5D995400C5B267 /* FSPagerCollectionView.swift */; };
|
||||
F9580B591E5D995400C5B267 /* FSPagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9580B531E5D995400C5B267 /* FSPagerView.swift */; };
|
||||
|
|
@ -49,6 +51,7 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPagerViewLayoutAttributes.swift; sourceTree = "<group>"; };
|
||||
F9580B511E5D995400C5B267 /* FSPageControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPageControl.swift; sourceTree = "<group>"; };
|
||||
F9580B521E5D995400C5B267 /* FSPagerCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPagerCollectionView.swift; sourceTree = "<group>"; };
|
||||
F9580B531E5D995400C5B267 /* FSPagerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FSPagerView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -111,6 +114,7 @@
|
|||
F9580B541E5D995400C5B267 /* FSPagerViewCell.swift */,
|
||||
F9580B551E5D995400C5B267 /* FSPageViewLayout.swift */,
|
||||
F9580B561E5D995400C5B267 /* FSPageViewTransformer.swift */,
|
||||
F95483991E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift */,
|
||||
);
|
||||
name = Sources;
|
||||
path = ../Sources;
|
||||
|
|
@ -322,6 +326,7 @@
|
|||
F9580B571E5D995400C5B267 /* FSPageControl.swift in Sources */,
|
||||
F9580B581E5D995400C5B267 /* FSPagerCollectionView.swift in Sources */,
|
||||
F9C6942F1E40C583007084B6 /* AppDelegate.swift in Sources */,
|
||||
F954839A1E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift in Sources */,
|
||||
F9580B591E5D995400C5B267 /* FSPagerView.swift in Sources */,
|
||||
F9C694351E40C583007084B6 /* PageControlExampleViewController.swift in Sources */,
|
||||
F9C694361E40C583007084B6 /* TransformerExampleViewController.swift in Sources */,
|
||||
|
|
@ -336,6 +341,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F954839B1E625F1E0069FD7E /* FSPagerViewLayoutAttributes.swift in Sources */,
|
||||
F9C6945A1E40C720007084B6 /* FSPagerViewExampleUITests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="65m-zG-Zjb">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="65m-zG-Zjb">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
|
|
@ -234,6 +234,9 @@
|
|||
<constraints>
|
||||
<constraint firstAttribute="width" secondItem="tSq-4e-Jil" secondAttribute="height" multiplier="375:193" id="8cc-kO-s6Y"/>
|
||||
</constraints>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="boolean" keyPath="isInfinite" value="YES"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="UOf-Wx-Dm5" id="Xcy-kf-B7Y"/>
|
||||
<outlet property="delegate" destination="UOf-Wx-Dm5" id="cQD-fS-FFJ"/>
|
||||
|
|
|
|||
|
|
@ -15,10 +15,16 @@ class FSPagerViewLayout: UICollectionViewLayout {
|
|||
internal var itemSpan: CGFloat = 0
|
||||
internal var needsReprepare = true
|
||||
|
||||
open override class var layoutAttributesClass: AnyClass {
|
||||
get {
|
||||
return FSPagerViewLayoutAttributes.self
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate var pagerView: FSPagerView? {
|
||||
return self.collectionView?.superview?.superview as? FSPagerView
|
||||
}
|
||||
fileprivate var layoutAttributes: [IndexPath:UICollectionViewLayoutAttributes] = [:]
|
||||
fileprivate var layoutAttributes: [IndexPath:FSPagerViewLayoutAttributes] = [:]
|
||||
|
||||
fileprivate var isInfinite: Bool = true
|
||||
fileprivate var collectionViewSize: CGSize = .zero
|
||||
|
|
@ -118,7 +124,7 @@ class FSPagerViewLayout: UICollectionViewLayout {
|
|||
let maxPosition = min(rect.maxX,self.contentSize.width-self.actualItemSize.width)
|
||||
while x <= maxPosition {
|
||||
let indexPath = IndexPath(item: itemIndex%self.numberOfItems, section: itemIndex/self.numberOfItems)
|
||||
let attributes = self.layoutAttributesForItem(at: indexPath)!
|
||||
let attributes = self.layoutAttributesForItem(at: indexPath) as! FSPagerViewLayoutAttributes
|
||||
self.applyTransform(to: attributes)
|
||||
layoutAttributes.append(attributes)
|
||||
itemIndex += 1
|
||||
|
|
@ -134,7 +140,9 @@ class FSPagerViewLayout: UICollectionViewLayout {
|
|||
if let attributes = self.layoutAttributes[indexPath] {
|
||||
return attributes
|
||||
}
|
||||
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
|
||||
let attributes = FSPagerViewLayoutAttributes(forCellWith: indexPath)
|
||||
attributes.itemSize = self.actualItemSize
|
||||
attributes.interitemSpacing = self.actualInteritemSpacing
|
||||
let x = self.frame(for: indexPath).minX
|
||||
let center = CGPoint(x: x+self.actualItemSize.width*0.5, y: collectionView.frame.height*0.5)
|
||||
attributes.center = center
|
||||
|
|
@ -217,7 +225,7 @@ class FSPagerViewLayout: UICollectionViewLayout {
|
|||
collectionView.bounds = newBounds
|
||||
}
|
||||
|
||||
fileprivate func applyTransform(to attributes: UICollectionViewLayoutAttributes) {
|
||||
fileprivate func applyTransform(to attributes: FSPagerViewLayoutAttributes) {
|
||||
guard let collectionView = self.collectionView else {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,8 @@ open class FSPagerViewTransformer: NSObject {
|
|||
}
|
||||
|
||||
// Apply transform to attributes - zIndex: Int, frame: CGRect, alpha: CGFloat, transform: CGAffineTransform or transform3D: CATransform3D.
|
||||
open func applyTransform(to attributes: UICollectionViewLayoutAttributes, for position: CGFloat) {
|
||||
guard let pagerView = self.pagerView else {
|
||||
return
|
||||
}
|
||||
let itemSpan = pagerView.collectionViewLayout.itemSpan
|
||||
open func applyTransform(to attributes: FSPagerViewLayoutAttributes, for position: CGFloat) {
|
||||
let itemSpan = attributes.interitemSpacing + attributes.itemSize.width
|
||||
switch self.type {
|
||||
case .none:
|
||||
break
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// FSPagerViewLayoutAttributes.swift
|
||||
// FSPagerViewExample
|
||||
//
|
||||
// Created by Wenchao Ding on 26/02/2017.
|
||||
// Copyright © 2017 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
open class FSPagerViewLayoutAttributes: UICollectionViewLayoutAttributes {
|
||||
|
||||
open var itemSize: CGSize = .zero
|
||||
open var interitemSpacing: CGFloat = 0
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue