Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将视图内左右间距参数开放出来,在一屏多图滑动时可在外部设置距离,不设置使用默认居中展示 #285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/FSPageViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ 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 = {
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
Expand Down
8 changes: 8 additions & 0 deletions Sources/FSPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down