Skip to content

Commit

Permalink
fix zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Dec 28, 2019
1 parent 99bb69b commit 7e30a31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions CollectionKit2/Sources/CollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ open class CollectionView: UIScrollView {
_loadCells(reloading: false)
}
contentView?.frame = CGRect(origin: .zero, size: contentSize)
ensureZoomViewIsCentered()
}


public func ensureZoomViewIsCentered() {
guard let contentView = contentView else { return }
let boundsSize = bounds.inset(by: adjustedContentInset)
var frameToCenter = contentView.frame

if frameToCenter.size.width < boundsSize.width {
frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) * 0.5
} else {
frameToCenter.origin.x = 0
}

if frameToCenter.size.height < boundsSize.height {
frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) * 0.5
} else {
frameToCenter.origin.y = 0
}

contentView.frame = frameToCenter
}

public func setNeedsReload() {
Expand Down
2 changes: 1 addition & 1 deletion CollectionKit2/Sources/Layout/FlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

public class FlowLayout: SortedLayoutProvider {
open class FlowLayout: SortedLayoutProvider {
public var lineSpacing: CGFloat
public var interitemSpacing: CGFloat

Expand Down

0 comments on commit 7e30a31

Please sign in to comment.