This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CollectionViewRow { | |
... | |
var rowWidth: CGFloat { | |
return attributes.reduce(0, { result, attribute -> CGFloat in | |
return result + attribute.frame.width | |
}) + CGFloat(attributes.count - 1) * spacing | |
} | |
func centerLayout(collectionViewWidth: CGFloat) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
... | |
var rows = [CollectionViewRow]() | |
var currentRowY: CGFloat = -1 | |
for attribute in attributes { | |
if currentRowY != attribute.frame.origin.y { | |
currentRowY = attribute.frame.origin.y | |
rows.append(CollectionViewRow(spacing: 10)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CollectionViewRow { | |
var attributes = [UICollectionViewLayoutAttributes]() | |
var spacing: CGFloat = 0 | |
init(spacing: CGFloat) { | |
self.spacing = spacing | |
} | |
func add(attribute: UICollectionViewLayoutAttributes) { | |
attributes.append(attribute) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
guard let attributes = super.layoutAttributesForElements(in: rect) else { | |
return nil | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let layout = UICollectionViewFlowLayout() | |
layout.estimatedItemSize = CGSize(width: 140, height: 40) | |
collectionView.collectionViewLayout = layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let data = self.pdfDocument.dataRepresentation() else { return } | |
let activityController = UIActivityViewController(activityItems: [data], applicationActivities: nil) | |
self.present(activityController, animated: true, completion: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open func dataRepresentation() -> Data? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open func insert(_ page: PDFPage, at index: Int) | |
open func removePage(at index: Int) | |
open func exchangePage(at indexA: Int, withPageAt indexB: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let url = URL(string:"www.your_pdf_url.com") else { return } | |
let pdfView = PDFView(frame: view.frame) | |
let pdfDocument = PDFDocument(url: url) | |
pdfView.document = pdfDocument | |
view.addSubview(pdfView) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView.animateKeyframes(withDuration: 5.0, delay: 0, options: [.calculationModeCubic], animations: { | |
// Add animations | |
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1.0/5.0, animations: { | |
view.frame.origin.x += 200 | |
}) | |
UIView.addKeyframe(withRelativeStartTime: 1.0/5.0, relativeDuration: 1.0/5.0, animations: { | |
view.backgroundColor = .green | |
}) | |
UIView.addKeyframe(withRelativeStartTime: 2.0/5.0, relativeDuration: 1.0/5.0, animations: { | |
view.frame.origin.y += 200 |
NewerOlder