From 0bedae1073d987983e9c536b81e2bc5a101ddb04 Mon Sep 17 00:00:00 2001 From: EvenYan Date: Wed, 1 Jul 2020 16:59:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B0=86=E8=A7=86=E5=9B=BE=E5=86=85?= =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E9=97=B4=E8=B7=9D=E5=8F=82=E6=95=B0=E5=BC=80?= =?UTF-8?q?=E6=94=BE=E5=87=BA=E6=9D=A5=EF=BC=8C=E5=9C=A8=E4=B8=80=E5=B1=8F?= =?UTF-8?q?=E5=A4=9A=E5=9B=BE=E6=BB=91=E5=8A=A8=E6=97=B6=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E7=A9=BA0.5=E4=B8=AAitem=E8=B7=9D=E7=A6=BB?= =?UTF-8?q?=20=E5=B7=B2=E8=A7=A3=E5=86=B3=E4=B8=8B=E9=9D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20https://github.com/WenchaoD/FSPagerView/issues/212?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FSPageViewLayout.swift | 2 +- Sources/FSPagerView.swift | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/FSPageViewLayout.swift b/Sources/FSPageViewLayout.swift index 9477ac4..4813cd8 100644 --- a/Sources/FSPageViewLayout.swift +++ b/Sources/FSPageViewLayout.swift @@ -75,7 +75,7 @@ class FSPagerViewLayout: UICollectionViewLayout { return pagerView.interitemSpacing }() self.scrollDirection = pagerView.scrollDirection - self.leadingSpacing = self.scrollDirection == .horizontal ? (collectionView.frame.width-self.actualItemSize.width)*0.5 : (collectionView.frame.height-self.actualItemSize.height)*0.5 + self.leadingSpacing = pagerView.leadingSpacing self.itemSpacing = (self.scrollDirection == .horizontal ? self.actualItemSize.width : self.actualItemSize.height) + self.actualInteritemSpacing // Calculate and cache contentSize, rather than calculating each time diff --git a/Sources/FSPagerView.swift b/Sources/FSPagerView.swift index 7fb17d9..d661a74 100644 --- a/Sources/FSPagerView.swift +++ b/Sources/FSPagerView.swift @@ -192,6 +192,14 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega } } + /// The spacing to use leading items in the pager view. Default is 0. + @IBInspectable + open var leadingSpacing: CGFloat = 0 { + didSet { + self.collectionViewLayout.forceInvalidate() + } + } + // MARK: - Public readonly-properties /// Returns whether the user has touched the content to initiate scrolling. From d3260fcefcd781a92b6b989d3794ec70099ff72d Mon Sep 17 00:00:00 2001 From: EvenYan Date: Sun, 5 Jul 2020 00:10:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=B7=A6=E5=8F=B3?= =?UTF-8?q?=E9=97=B4=E8=B7=9D=E5=B1=9E=E6=80=A7=E5=BC=80=E6=94=BE=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E4=B8=AD=E9=97=B4=E5=9B=BE=E7=89=87=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=89=A7=E4=B8=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FSPageViewLayout.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/FSPageViewLayout.swift b/Sources/FSPageViewLayout.swift index 4813cd8..5de2156 100644 --- a/Sources/FSPageViewLayout.swift +++ b/Sources/FSPageViewLayout.swift @@ -75,7 +75,15 @@ class FSPagerViewLayout: UICollectionViewLayout { return pagerView.interitemSpacing }() self.scrollDirection = pagerView.scrollDirection - self.leadingSpacing = pagerView.leadingSpacing + + self.leadingSpacing = { + var spacing = pagerView.leadingSpacing + if spacing == .zero { + spacing = self.scrollDirection == .horizontal ? (collectionView.frame.width-self.actualItemSize.width)*0.5 : (collectionView.frame.height-self.actualItemSize.height)*0.5 + } + return spacing + }() + self.itemSpacing = (self.scrollDirection == .horizontal ? self.actualItemSize.width : self.actualItemSize.height) + self.actualInteritemSpacing // Calculate and cache contentSize, rather than calculating each time