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

add right button and single tap to show/hide navibar #3

Open
wants to merge 6 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
8 changes: 4 additions & 4 deletions IPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = "IPhotoBrowser"
s.version = "0.6.0"
s.version = "0.1.3"
s.summary = "A simple iOS Instagram photo browser written in Swift."
s.homepage = "https://github.com/hryk224/IPhotoBrowser"
s.homepage = "https://github.com/longhoang2984/LHIPhotoBrowser"
s.screenshots = "https://github.com/hryk224/IPhotoBrowser/wiki/images/sample1.gif"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "hyyk224" => "[email protected]" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/hryk224/IPhotoBrowser.git", :tag => "#{s.version}" }
s.source = { :git => "https://github.com/longhoang2984/LHIPhotoBrowser.git", :tag => "#{s.version}" }
s.source_files = "Sources/*.{h,swift}"
s.frameworks = "UIKit", "Photos"
s.requires_arc = true
end
end
Empty file modified Sources/IPhoto.swift
100644 → 100755
Empty file.
Empty file modified Sources/IPhotoBrowser.h
100644 → 100755
Empty file.
63 changes: 57 additions & 6 deletions Sources/IPhotoBrowser.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,39 @@ open class IPhotoBrowser: UIViewController {
self.modalPresentationCapturesStatusBarAppearance = true
self.sourceType = .image
}
public convenience init(imageUrls: [URL], start index:Int) {
public convenience init(imageUrls: [URL], start index:Int, isHaveRightButton: Bool = false) {
self.init(nibName: nil, bundle: nil)
self.imageUrls = imageUrls
self.index = index
self.transitioningDelegate = self
self.modalPresentationStyle = .overCurrentContext
self.modalPresentationCapturesStatusBarAppearance = true
self.sourceType = .imageUrl
self.isHaveRightButton = isHaveRightButton
}
public convenience init(assets: [PHAsset], start index:Int) {
public convenience init(assets: [PHAsset], start index:Int, isHaveRightButton: Bool = false) {
self.init(nibName: nil, bundle: nil)
self.assets = assets
self.index = index
self.transitioningDelegate = self
self.modalPresentationStyle = .overCurrentContext
self.modalPresentationCapturesStatusBarAppearance = true
self.sourceType = .asset
self.isHaveRightButton = isHaveRightButton
}
public convenience init(photos: [IPhoto], start index:Int) {
public convenience init(photos: [IPhoto], start index:Int, isHaveRightButton: Bool = false) {
self.init(nibName: nil, bundle: nil)
self.photos = photos
self.index = index
self.transitioningDelegate = self
self.modalPresentationStyle = .overCurrentContext
self.modalPresentationCapturesStatusBarAppearance = true
self.sourceType = .iPhoto
self.isHaveRightButton = isHaveRightButton
}
// Private property
var segueType: SegueType = .pushed
fileprivate var isHaveRightButton : Bool = false
fileprivate var sourceType: IPhotoBrowserSourceType = .image
fileprivate var backgroundColor: UIColor = .black // Default
fileprivate var itemColor: UIColor = .white // Default
Expand All @@ -130,14 +134,47 @@ open class IPhotoBrowser: UIViewController {
let navigationBarHeight = UINavigationBar().intrinsicContentSize.height
let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: navigationBarHeight + statusBarHeight))
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.backgroundColor = .clear
navigationBar.shadowImage = UIImage()

let gradientLayer = CAGradientLayer()
gradientLayer.frame = CGRect(x: 0, y: 0, width: navigationBar.bounds.width, height: navigationBar.bounds.height + statusBarHeight)
gradientLayer.zPosition = -1

var colors = [CGColor]()
var locations = [NSNumber]()
let limitNumber = 100
for i in 0..<limitNumber {

let floatNumber = CGFloat(i) / CGFloat(limitNumber)

let color = UIColor(white: 0, alpha: floatNumber).cgColor
let location : NSNumber = floatNumber as NSNumber

locations.append(location)
colors.insert(color, at: 0)
}

gradientLayer.colors = colors
gradientLayer.locations = locations

navigationBar.layer.addSublayer(gradientLayer)
navigationBar.barTintColor = .clear
navigationBar.isTranslucent = true
navigationBar.tintColor = itemColor
let navigationItem = IPhotoNavigationItem(title: "")
let barButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(IPhotoBrowser.dismissAction))
let leftButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
leftButton.setImage(#imageLiteral(resourceName: "ic_Cancel"), for: .normal)
leftButton.contentHorizontalAlignment = .left
leftButton.addTarget(self, action: #selector(IPhotoBrowser.dismissAction), for: .touchUpInside)
let barButtonItem = UIBarButtonItem(customView: leftButton)
navigationItem.leftBarButtonItem = barButtonItem
if isHaveRightButton {
let rightButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_more_image"), style: .plain, target: self, action: #selector(IPhotoBrowser.touchRightButton(_:)))
navigationItem.rightBarButtonItem = rightButton
}
navigationBar.setItems([navigationItem], animated: false)

navigationItem.tintColor = itemColor
navigationBar.alpha = 0
view.addSubview(navigationBar)
Expand All @@ -147,6 +184,7 @@ open class IPhotoBrowser: UIViewController {
setTitle()
showItemViews(true, delay: 0.3)
}

open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch segueType {
Expand Down Expand Up @@ -227,7 +265,7 @@ extension IPhotoBrowser: UICollectionViewDelegate, UICollectionViewDataSource {
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: IPhotoBrowserCollectionViewCell.identifier, for: indexPath) as! IPhotoBrowserCollectionViewCell
cell.delegate = self
cell.setUp(description: descriptionItemColor.textColor, backgroundColor: descriptionItemColor.backgroundColor)
//cell.setUp(description: descriptionItemColor.textColor, backgroundColor: descriptionItemColor.backgroundColor)
switch sourceType {
case .image:
cell.configure(image: images[indexPath.item])
Expand Down Expand Up @@ -262,6 +300,10 @@ extension IPhotoBrowser: UICollectionViewDelegate, UICollectionViewDataSource {
guard segueType.isPushed else { return }
setScreenshot()
}

public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("abv")
}
}

// MARK: - IPhotoBrowserCollectionViewCellDelegate
Expand Down Expand Up @@ -309,6 +351,10 @@ extension IPhotoBrowser: IPhotoBrowserCollectionViewCellDelegate {
showItemViews(!isZooming)
collectionView.isScrollEnabled = !isZooming
}

func cellImageToggleItemsView(_ cell: IPhotoBrowserCollectionViewCell, isShow: Bool) {
showItemViews(isShow)
}
}

// MARK: - UIViewControllerTransitioningDelegate
Expand Down Expand Up @@ -417,6 +463,11 @@ private extension IPhotoBrowser {
}
dynamic func dismissAction() {
showItemViews(false)
UIApplication.shared.isStatusBarHidden = false
dismiss(animated: true, completion: nil)
}

dynamic func touchRightButton(_ sender: Any) {
delegate?.iPhotoBrowserTouchRightButton?(self, selectedItemAt: index)
}
}
Empty file modified Sources/IPhotoBrowserAnimatedTransition.swift
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions Sources/IPhotoBrowserCollectionViewCell.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol IPhotoBrowserCollectionViewCellDelegate: class {
func cellImageViewDidEndDragging(_ cell: IPhotoBrowserCollectionViewCell, isClosed: Bool)
func cellImageViewDidEndCancelAnimation(_ cell: IPhotoBrowserCollectionViewCell)
func cellImageViewDidZooming(_ cell: IPhotoBrowserCollectionViewCell, isZooming: Bool)
func cellImageToggleItemsView(_ cell: IPhotoBrowserCollectionViewCell, isShow: Bool)
}

class IPhotoBrowserCollectionViewCell: UICollectionViewCell {
Expand Down Expand Up @@ -50,6 +51,10 @@ class IPhotoBrowserCollectionViewCell: UICollectionViewCell {
imageView.addGestureRecognizer(self.panGestureRecognizer)
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(IPhotoBrowserCollectionViewCell.handleGestureImageDoubleTap))
doubleTapGestureRecognizer.numberOfTapsRequired = 2

let singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(IPhotoBrowserCollectionViewCell.handleGestureImageSingleTap(_:)))

imageView.addGestureRecognizer(singleTapGestureRecognizer)
imageView.addGestureRecognizer(doubleTapGestureRecognizer)
return imageView
}
Expand Down Expand Up @@ -83,6 +88,7 @@ class IPhotoBrowserCollectionViewCell: UICollectionViewCell {
fileprivate let panGestureRecognizer = UIPanGestureRecognizer()
fileprivate var indexPath: IndexPath?
fileprivate var itemViews: [UIView] = []
fileprivate var isShowItems = true
weak var delegate: IPhotoBrowserCollectionViewCellDelegate?
override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -237,6 +243,12 @@ private extension IPhotoBrowserCollectionViewCell {
let ratio = fabs((view.center.y - (originalCenter.y)) / ((originalCenter.y)))
delegate?.cellImageViewDidDragging(self, ratio: ratio)
}

dynamic func handleGestureImageSingleTap(_ gestureRecognizer: UITapGestureRecognizer) {
self.isShowItems = self.isShowItems ? false : true
delegate?.cellImageToggleItemsView(self, isShow: self.isShowItems)
}

dynamic func handleGestureImageDoubleTap(_ gestureRecognizer: UITapGestureRecognizer) {
guard scrollView.minimumZoomScale == scrollView.zoomScale else {
scrollView.setZoomScale(scrollView.minimumZoomScale, animated: true)
Expand Down
Empty file modified Sources/IPhotoBrowserCollectionViewFlowLayout.swift
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions Sources/IPhotoBrowserDelegate.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ import UIKit
@objc optional func iPhotoBrowserDidPop(_ iPhotoBrowser: IPhotoBrowser)
@objc optional func iPhotoBrowserDidCanceledPop(_ iPhotoBrowser: IPhotoBrowser)
@objc optional func iPhotoBrowserMakeViewScreenshotIfNeeded(_ iPhotoBrowser: IPhotoBrowser) -> UIImage?
@objc optional func iPhotoBrowserTouchRightButton(_ iPhotoBrowser: IPhotoBrowser, selectedItemAt index: Int)
}
Empty file modified Sources/IPhotoBrowserNavigationController.swift
100644 → 100755
Empty file.
Empty file modified Sources/IPhotoNavigationItem.swift
100644 → 100755
Empty file.
Empty file modified Sources/IPhotoWebImageCache.swift
100644 → 100755
Empty file.
Empty file modified Sources/PHAsset+IPhotoBrowser.swift
100644 → 100755
Empty file.
Empty file modified Sources/UIImageView+IPhotoBrowser.swift
100644 → 100755
Empty file.
Empty file modified Sources/UIView+IPhotoBrowser.swift
100644 → 100755
Empty file.
Binary file added sample1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.