Skip to content

Commit

Permalink
- deleted header/footer
Browse files Browse the repository at this point in the history
- fixed invalidateLayout method
  • Loading branch information
KhrystynaShevchuk committed Jul 5, 2017
1 parent 115a990 commit 88dc258
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 70 deletions.
6 changes: 2 additions & 4 deletions PinterestLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
640095F71F0BC37F006AE391 /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640095F61F0BC37F006AE391 /* CollectionViewCell.swift */; };
644F27AA1F0BF039004AD5AD /* RoundedCornersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 644F27A91F0BF039004AD5AD /* RoundedCornersView.swift */; };
646A48511F0CEFDB00088AD0 /* PinterestLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EF21F0BB1D200DAA3B7 /* PinterestLayout.swift */; };
B572E5EF1F0C20D100540F7C /* PinterestHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B572E5EE1F0C20D100540F7C /* PinterestHeader.swift */; };
B5AFCBAC1F0BB16F00CB71B5 /* PinterestLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = B5AFCBAA1F0BB16F00CB71B5 /* PinterestLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
B5CF9EDE1F0BB19500DAA3B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EDD1F0BB19500DAA3B7 /* AppDelegate.swift */; };
Expand All @@ -18,7 +19,6 @@
B5CF9EE81F0BB19500DAA3B7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B5CF9EE61F0BB19500DAA3B7 /* LaunchScreen.storyboard */; };
B5CF9EED1F0BB1A800DAA3B7 /* PinterestLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5AFCBA71F0BB16F00CB71B5 /* PinterestLayout.framework */; };
B5CF9EEE1F0BB1A800DAA3B7 /* PinterestLayout.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B5AFCBA71F0BB16F00CB71B5 /* PinterestLayout.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
B5CF9EF31F0BB1D200DAA3B7 /* PinterestLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CF9EF21F0BB1D200DAA3B7 /* PinterestLayout.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -276,14 +276,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B5CF9EF31F0BB1D200DAA3B7 /* PinterestLayout.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
B5CF9ED71F0BB19500DAA3B7 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
646A48511F0CEFDB00088AD0 /* PinterestLayout.swift in Sources */,
B5CF9EE01F0BB19500DAA3B7 /* PinterestVC.swift in Sources */,
B5CF9EDE1F0BB19500DAA3B7 /* AppDelegate.swift in Sources */,
640095F71F0BC37F006AE391 /* CollectionViewCell.swift in Sources */,
Expand Down Expand Up @@ -469,7 +469,6 @@
B5CF9EEA1F0BB19500DAA3B7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = SWXVWAU9H9;
INFOPLIST_FILE = PinterestLayoutExample/Info.plist;
Expand All @@ -484,7 +483,6 @@
B5CF9EEB1F0BB19500DAA3B7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = SWXVWAU9H9;
INFOPLIST_FILE = PinterestLayoutExample/Info.plist;
Expand Down
7 changes: 4 additions & 3 deletions PinterestLayout/PinterestLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ public class PinterestLayout: UICollectionViewLayout {
}


public override func invalidateLayout() {
super.invalidateLayout()

override public func invalidateLayout() {
cache.removeAll()
contentHeight = 0

super.invalidateLayout()
}

override public func prepare() {
Expand Down
2 changes: 1 addition & 1 deletion PinterestLayoutExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<collectionViewLayout key="collectionViewLayout" id="JpX-bG-ugo" customClass="PinterestLayout" customModule="PinterestLayout"/>
<collectionViewLayout key="collectionViewLayout" id="JpX-bG-ugo" customClass="PinterestLayout" customModule="PinterestLayoutExample" customModuleProvider="target"/>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="CollectionCell" id="aff-Ju-D2b" customClass="CollectionViewCell" customModule="PinterestLayoutExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="175" height="273"/>
Expand Down
2 changes: 0 additions & 2 deletions PinterestLayoutExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
Expand Down
67 changes: 7 additions & 60 deletions PinterestLayoutExample/PinterestVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,16 @@ import AVFoundation

class PinterestVC: UICollectionViewController {

var images: [[UIImage]] = [
[#imageLiteral(resourceName: "new_york"), #imageLiteral(resourceName: "bigben_river"), #imageLiteral(resourceName: "dubai"), #imageLiteral(resourceName: "4"), #imageLiteral(resourceName: "tiger"), #imageLiteral(resourceName: "5")],
[#imageLiteral(resourceName: "adelaide_castle"), #imageLiteral(resourceName: "rys"), #imageLiteral(resourceName: "12"), #imageLiteral(resourceName: "cat"), #imageLiteral(resourceName: "6"), #imageLiteral(resourceName: "city"), #imageLiteral(resourceName: "9"), #imageLiteral(resourceName: "ph"), #imageLiteral(resourceName: "paris"), #imageLiteral(resourceName: "2"), #imageLiteral(resourceName: "bridge"), #imageLiteral(resourceName: "elephants")],
[#imageLiteral(resourceName: "venice"), #imageLiteral(resourceName: "bw_new_york"), #imageLiteral(resourceName: "10"), #imageLiteral(resourceName: "kittens"), #imageLiteral(resourceName: "deer"), #imageLiteral(resourceName: "11"), #imageLiteral(resourceName: "8"), #imageLiteral(resourceName: "13"), #imageLiteral(resourceName: "squirell"), #imageLiteral(resourceName: "lion"), #imageLiteral(resourceName: "nature"), #imageLiteral(resourceName: "4")]
]
var images: [UIImage] = [#imageLiteral(resourceName: "new_york"), #imageLiteral(resourceName: "bigben_river"), #imageLiteral(resourceName: "dubai"), #imageLiteral(resourceName: "4"), #imageLiteral(resourceName: "tiger"), #imageLiteral(resourceName: "5"), #imageLiteral(resourceName: "adelaide_castle"), #imageLiteral(resourceName: "rys"), #imageLiteral(resourceName: "12"), #imageLiteral(resourceName: "cat"), #imageLiteral(resourceName: "6"), #imageLiteral(resourceName: "city"), #imageLiteral(resourceName: "9"), #imageLiteral(resourceName: "ph"), #imageLiteral(resourceName: "paris"), #imageLiteral(resourceName: "2"), #imageLiteral(resourceName: "bridge"), #imageLiteral(resourceName: "elephants"), #imageLiteral(resourceName: "venice"), #imageLiteral(resourceName: "bw_new_york"), #imageLiteral(resourceName: "10"), #imageLiteral(resourceName: "kittens"), #imageLiteral(resourceName: "deer"), #imageLiteral(resourceName: "11"), #imageLiteral(resourceName: "8"), #imageLiteral(resourceName: "13"), #imageLiteral(resourceName: "squirell"), #imageLiteral(resourceName: "lion"), #imageLiteral(resourceName: "nature"), #imageLiteral(resourceName: "4")]


override func viewDidLoad() {
super.viewDidLoad()

setupCollectionViewInsets()
setupLayout()

collectionView?.register(
PinterestHeader.self,
forSupplementaryViewOfKind: UICollectionElementKindSectionHeader,
withReuseIdentifier: "PinterestHeader"
)
collectionView?.register(
PinterestHeader.self,
forSupplementaryViewOfKind: UICollectionElementKindSectionFooter,
withReuseIdentifier: "PinterestHeader"
)
}



//MARK: private

private func setupCollectionViewInsets() {
Expand All @@ -63,41 +48,20 @@ class PinterestVC: UICollectionViewController {

extension PinterestVC {

override func numberOfSections(in collectionView: UICollectionView) -> Int {
return images.count
}

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(
ofKind: kind,
withReuseIdentifier: "PinterestHeader",
for: indexPath
)

if kind == UICollectionElementKindSectionHeader {
header.backgroundColor = UIColor.red
} else {
header.backgroundColor = UIColor.green
}

return header
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images[section].count
return images.count
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let image = images[indexPath.section][indexPath.item]
let image = images[indexPath.item]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! CollectionViewCell
cell.image = image

// bad way of setting text, but just for a test
if indexPath.item % 2 == 0 {
cell.descriptionLabel.text = "Very short description"
} else {
cell.descriptionLabel.text = "Tonight, there are no lovers walking down the park alleys. There are no kings in the castles, and the princesses die alone – they have no frogs or peas. Tonight, the inkpots are empty, and the words are uncountable. Tonight, all shouts are muffled by unbearable silence."
cell.descriptionLabel.text = "Tonight, there are no lovers walking down the park alleys. There are no kings in the castles, and the princesses die alone – they have no frogs or peas. Tonight, the inkpots are empty, and the words are uncountable. Tonight, all shouts are muffled by unbearable silence..."
}

return cell
Expand All @@ -109,27 +73,10 @@ extension PinterestVC {

extension PinterestVC: CollectionViewLayoutDelegate {

func collectionView(collectionView: UICollectionView,
sizeForSectionHeaderViewForSection section: Int) -> CGSize {
let width = collectionView.frame.width - collectionView.contentInset.left - collectionView.contentInset.right
return CGSize(
width: width,
height: 20
)
}

func collectionView(collectionView: UICollectionView,
sizeForSectionFooterViewForSection section: Int) -> CGSize {
return CGSize(
width: collectionView.frame.width,
height: 20
)
}

func collectionView(collectionView: UICollectionView,
heightForImageAtIndexPath indexPath: IndexPath,
withWidth: CGFloat) -> CGFloat {
let image = images[indexPath.section][indexPath.item]
let image = images[indexPath.item]
let boundingRect = CGRect(x: 0, y: 0, width: withWidth, height: CGFloat(MAXFLOAT))
let rect = AVMakeRect(aspectRatio: image.size, insideRect: boundingRect)
return rect.height
Expand Down

0 comments on commit 88dc258

Please sign in to comment.