Skip to content

Commit

Permalink
Merge pull request #18 from jane/task/rotationIssue
Browse files Browse the repository at this point in the history
Fixed rotation issue
  • Loading branch information
gordontucker authored Dec 13, 2016
2 parents 1e5ef23 + d8e1c74 commit 9ce7286
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions JanePhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = "JanePhotoBrowser"
s.version = "0.2.6"
s.version = "0.2.8"
s.summary = "The Jane Photo Browser is a simple way to browse a group of photos"
s.homepage = "https://github.com/jane/JanePhotoBrowser"
s.license = 'MIT'
s.author = { "Jane" => "barlow@jane.com" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/jane/JanePhotoBrowser.git", :tag => "0.2.5" }
s.source = { :git => "https://github.com/jane/JanePhotoBrowser.git", :tag => "0.2.8" }
s.source_files = "JanePhotoBrowser/JanePhotoBrowser/Classes/*.swift"
s.exclude_files = "JanePhotoBrowser/JanePhotoBrowser/Classes/Exclude"
end
4 changes: 2 additions & 2 deletions JanePhotoBrowser/JanePhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.jane.JanePhotoBrowser;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -496,7 +496,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.jane.JanePhotoBrowser;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class PhotoBrowserCell:UICollectionViewCell, PhotoBrowserViewCell {

//Add ImageView constraints
self.imageView.translatesAutoresizingMaskIntoConstraints = false
let vImageConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|[view(\(self.frame.size.height))]", options: [], metrics: nil, views: ["view":self.imageView])
let hImageConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|[view(\(self.frame.size.width))]|", options: [], metrics: nil, views: ["view":self.imageView])
let vImageConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]", options: [], metrics: nil, views: ["view":self.imageView])
let hImageConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: ["view":self.imageView])
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]|", options: [], metrics: nil, views: ["view":self.scrollView])
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: ["view":self.scrollView])

Expand All @@ -64,6 +64,9 @@ class PhotoBrowserCell:UICollectionViewCell, PhotoBrowserViewCell {
self.addConstraints(vConstraints)
self.addConstraints(hConstraints)

self.addConstraint(NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: self.imageView, attribute: .height, multiplier: 1, constant: 0))
self.addConstraint(NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: self.imageView, attribute: .width, multiplier: 1, constant: 0))

//Add Tap Gesture to capture cell tap
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
self.scrollView.addGestureRecognizer(tap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PhotoBrowserTransition: NSObject, UIViewControllerAnimatedTransitioning {
containerView.addSubview(destinationViewController.view)
containerView.addSubview(snapShot)

if let selectedIndex:Int = originPhotoView?.visibleIndexPath()?.row {
if let selectedIndex:Int = originPhotoView?.visibleIndexPath()?.item {
photoView.scrollToPhoto(atIndex: selectedIndex, animated: false)
}

Expand Down
18 changes: 13 additions & 5 deletions JanePhotoBrowser/JanePhotoBrowser/Classes/PhotoBrowserView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ open class PhotoBrowserView:UIView {
}
open weak var delegate:PhotoBrowserDelegate?
var viewIsAnimating:Bool = false
var currentVisibleIndexPath: IndexPath?

//MARK: - IBInspectable
@IBInspectable open var canZoom:Bool = false {
Expand Down Expand Up @@ -93,8 +94,17 @@ open class PhotoBrowserView:UIView {
}

override open func layoutSubviews() {
let indexPath = self.currentVisibleIndexPath ?? self.visibleIndexPath()
super.layoutSubviews()
self.updateLabelView()

let layout = PhotoBrowserView.layout()
layout.itemSize = self.bounds.size
self.collectionView.collectionViewLayout = layout

if let visibleIndexPath = indexPath {
self.scrollToPhoto(atIndex: visibleIndexPath.item, animated: false)
}
}

//MARK: - Private PhotoBrowser Methods
Expand Down Expand Up @@ -190,6 +200,8 @@ open class PhotoBrowserView:UIView {
let indexPath:IndexPath = IndexPath(row: index, section: 0)
guard indexPath.row < self.collectionView.numberOfItems(inSection: 0) && indexPath.row >= 0 else { self.reloadPhotos(); return }
self.collectionView.scrollToItem(at: indexPath, at: [.centeredVertically, .centeredHorizontally], animated: animated)
self.currentVisibleIndexPath = indexPath

self.updateLabelView()
}

Expand All @@ -204,11 +216,11 @@ open class PhotoBrowserView:UIView {
}
open func visibleIndexPath() -> IndexPath? {
let indexPaths = self.collectionView.indexPathsForVisibleItems
print(indexPaths)
return indexPaths.first
}

open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
self.currentVisibleIndexPath = self.visibleIndexPath()
self.updateLabelView()
}

Expand Down Expand Up @@ -242,8 +254,4 @@ extension PhotoBrowserView:UICollectionViewDataSource, UICollectionViewDelegate,

return cell
}

public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return self.frame.size
}
}

0 comments on commit 9ce7286

Please sign in to comment.