Skip to content

Commit

Permalink
Merge pull request #1 from hryk224/v0.6.0
Browse files Browse the repository at this point in the history
Added title and description
  • Loading branch information
hryk224 committed Feb 27, 2017
2 parents 5e3c43c + 0625496 commit 3ebbfb6
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 36 deletions.
2 changes: 1 addition & 1 deletion IPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "IPhotoBrowser"
s.version = "0.5.0"
s.version = "0.6.0"
s.summary = "A simple iOS Instagram photo browser written in Swift."
s.homepage = "https://github.com/hryk224/IPhotoBrowser"
s.screenshots = "https://github.com/hryk224/IPhotoBrowser/wiki/images/sample1.gif"
Expand Down
2 changes: 1 addition & 1 deletion IPhotoBrowser.xcodeproj/IPhotoBrowser_Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.5.0</string>
<string>0.6.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
24 changes: 24 additions & 0 deletions IPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
9312AD8D1E5F327E00BEFD77 /* IPhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9312AD8C1E5F327E00BEFD77 /* IPhoto.swift */; };
9312AD901E5F394400BEFD77 /* IPhotoNavigationItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9312AD8F1E5F394400BEFD77 /* IPhotoNavigationItem.swift */; };
935281951E5CACB4006481EA /* IPhotoBrowserCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935281941E5CACB4006481EA /* IPhotoBrowserCollectionViewCell.swift */; };
935281971E5CACC6006481EA /* IPhotoBrowserDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935281961E5CACC6006481EA /* IPhotoBrowserDelegate.swift */; };
935281991E5CACCE006481EA /* IPhotoBrowserAnimatedTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935281981E5CACCE006481EA /* IPhotoBrowserAnimatedTransition.swift */; };
Expand All @@ -32,6 +34,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
9312AD8C1E5F327E00BEFD77 /* IPhoto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPhoto.swift; sourceTree = "<group>"; };
9312AD8F1E5F394400BEFD77 /* IPhotoNavigationItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPhotoNavigationItem.swift; sourceTree = "<group>"; };
935281811E5CAA4F006481EA /* IPhotoBrowser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IPhotoBrowser.h; sourceTree = "<group>"; };
935281941E5CACB4006481EA /* IPhotoBrowserCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPhotoBrowserCollectionViewCell.swift; sourceTree = "<group>"; };
935281961E5CACC6006481EA /* IPhotoBrowserDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPhotoBrowserDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -106,6 +110,22 @@
name = Utility;
sourceTree = "<group>";
};
9312AD8B1E5F326300BEFD77 /* Entity */ = {
isa = PBXGroup;
children = (
9312AD8C1E5F327E00BEFD77 /* IPhoto.swift */,
);
name = Entity;
sourceTree = "<group>";
};
9312AD8E1E5F392A00BEFD77 /* View */ = {
isa = PBXGroup;
children = (
9312AD8F1E5F394400BEFD77 /* IPhotoNavigationItem.swift */,
);
name = View;
sourceTree = "<group>";
};
937FFC7C1E5734270061ECC1 /* Transitions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -161,6 +181,8 @@
OBJ_7 /* Sources */ = {
isa = PBXGroup;
children = (
9312AD8E1E5F392A00BEFD77 /* View */,
9312AD8B1E5F326300BEFD77 /* Entity */,
930325291E563EAD00A6B9A2 /* CollectionViewCell */,
9303252C1E563EBF00A6B9A2 /* Controller */,
930325351E563ECC00A6B9A2 /* Extension */,
Expand Down Expand Up @@ -244,10 +266,12 @@
files = (
9352819D1E5CACE2006481EA /* IPhotoBrowser.swift in Sources */,
935281991E5CACCE006481EA /* IPhotoBrowserAnimatedTransition.swift in Sources */,
9312AD8D1E5F327E00BEFD77 /* IPhoto.swift in Sources */,
935281951E5CACB4006481EA /* IPhotoBrowserCollectionViewCell.swift in Sources */,
9352819E1E5CACE2006481EA /* IPhotoBrowserCollectionViewFlowLayout.swift in Sources */,
935281971E5CACC6006481EA /* IPhotoBrowserDelegate.swift in Sources */,
9352819F1E5CACE2006481EA /* IPhotoBrowserNavigationController.swift in Sources */,
9312AD901E5F394400BEFD77 /* IPhotoNavigationItem.swift in Sources */,
935281A71E5CAD0A006481EA /* IPhotoWebImageCache.swift in Sources */,
935281A31E5CACFC006481EA /* PHAsset+IPhotoBrowser.swift in Sources */,
935281A41E5CACFC006481EA /* UIImageView+IPhotoBrowser.swift in Sources */,
Expand Down
28 changes: 27 additions & 1 deletion IPhotoBrowserExample/IPhotoBrowserExample/Sources/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit.UIImage
import UIKit.UIColor
import IPhotoBrowser

struct Assets {
struct Image {
Expand All @@ -30,11 +31,36 @@ struct Assets {
}
private init() {
objects = countableRange
// .map { "https://github.com/hryk224/IPhotoBrowser/wiki/images/0" + String($0) + ".jpg" }
.map { "https://dummyimage.com/200x200/\(UIColor.random.toHexString)&text=" + String($0) }
.flatMap { URL(string: $0) }
}
}
struct Photo {
static let share: Assets.Photo = Photo()
let objects: [IPhoto]
private let countableRange: CountableRange<Int> = 1..<36
var count: Int {
return countableRange.count
}
private init() {
let count = countableRange.count
let descriptions: [String] = [
"It is a sample string. It is a sample string. It is a sample string. It is a sample string. It is a sample string.",
"サンプル文字列です。サンプル文字列です。サンプル文字列です。サンプル文字列です。サンプル文字列です。",
"它是一个示例字符串。 它是一个示例字符串。 它是一个示例字符串。 它是一个示例字符串。 它是一个示例字符串。",
"Quod est a sample nervo. Quod est a sample nervo. Quod est a sample nervo. Quod est a sample nervo. Quod est a sample nervo.",
"Es ist ein Beispielstring. Es ist ein Beispielstring. Es ist ein Beispielstring. Es ist ein Beispielstring. Es ist ein Beispielstring.",
"샘플 문자열입니다. 샘플 문자열입니다. 샘플 문자열입니다. 샘플 문자열입니다. 샘플 문자열입니다."
]
objects = countableRange.enumerated()
.flatMap { ($0 + 1, UIImage(named: String($1))!) }
.map {
IPhoto(image: $1,
title: "\($0)/\(count)",
description: descriptions[$0 % descriptions.count])
}
}
}
}

private extension UIColor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class CameraRollViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
photosRequestAuthorization()
title = MainViewController.Row.cameraRoll.title
}
}

Expand Down Expand Up @@ -85,8 +86,9 @@ extension CameraRollViewController: UICollectionViewDelegate, UICollectionViewDa
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let photoBrowser = IPhotoBrowser(assets: photos.map { $0.asset }, start: indexPath.item)
photoBrowser.configure(backgroundColor: .white)
photoBrowser.delegate = self
photoBrowser.configure(backgroundColor: .white)
photoBrowser.configure(itemColor: .black)
present(photoBrowser, animated: true, completion: nil)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@ class HorizontalViewController: UIViewController {
collectionView.register(AssetCollectionViewCell.nib, forCellWithReuseIdentifier: AssetCollectionViewCell.identifier)
}
}
fileprivate var images: Assets.Image {
return Assets.Image.share
fileprivate var photos: Assets.Photo {
return Assets.Photo.share
}
static func makeFromStoryboard() -> HorizontalViewController {
let storyboard = UIStoryboard(name: "HorizontalViewController", bundle: nil)
return storyboard.instantiateInitialViewController() as! HorizontalViewController
}
override func viewDidLoad() {
super.viewDidLoad()
title = MainViewController.Row.horizontal.title
}
}

// MARK: - UICollectionViewDelegate, UICollectionViewDataSource
extension HorizontalViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
return photos.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: AssetCollectionViewCell.identifier, for: indexPath) as! AssetCollectionViewCell
cell.configure(image: images.objects[indexPath.item])
cell.configure(image: photos.objects[indexPath.item].image)
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let photoBrowser = IPhotoBrowser(images: images.objects, start: indexPath.item)
let photoBrowser = IPhotoBrowser(photos: photos.objects, start: indexPath.item)
photoBrowser.delegate = self
present(photoBrowser, animated: true, completion: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ final class InAppImageViewController: UIViewController {
let storyboard = UIStoryboard(name: "InAppImageViewController", bundle: nil)
return storyboard.instantiateInitialViewController() as! InAppImageViewController
}
override func viewDidLoad() {
super.viewDidLoad()
title = MainViewController.Row.inAppImage.title
}
}

// MARK: - UICollectionViewDelegate, UICollectionViewDataSource
Expand All @@ -50,7 +54,10 @@ extension InAppImageViewController: UICollectionViewDelegate, UICollectionViewDa
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let photoBrowser = IPhotoBrowser(images: images.objects, start: indexPath.item)
let photos = images.objects.enumerated()
.flatMap { ($0 + 1, $1) }
.flatMap { IPhoto(image: $1, title: "\($0)/\(images.count)") }
let photoBrowser = IPhotoBrowser(photos: photos, start: indexPath.item)
photoBrowser.delegate = self
navigationController?.pushViewController(photoBrowser, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ final class MainViewController: UIViewController {
enum Row: Int, CustomStringConvertible {
case inAppImage = 0, cameraRoll, horizontal, imageUrl
static var count = 4
var title: String {
switch self {
case .inAppImage, .horizontal: return "In-app"
case .cameraRoll: return "Camera"
case .imageUrl: return "Imageurl"
}
}
var description: String {
switch self {
case .inAppImage: return "In-app images"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class ImageUrlViewController: UITableViewController {
super.viewDidLoad()
tableView.register(WebImageTableViewCell.nib, forCellReuseIdentifier: WebImageTableViewCell.identifier)
tableView.separatorInset = .zero
title = MainViewController.Row.imageUrl.title
}
}

Expand Down
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ A simple iOS Instagram photo browser written in Swift.
[![CocoaPods Compatible](http://img.shields.io/cocoapods/v/IPhotoBrowser.svg?style=flat)](http://cocoadocs.org/docsets/IPhotoBrowser)
[![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/)

<img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample1.gif" width="320" >
<img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample1.gif" width="320" > <img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample2.gif" width="320" >

<img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample2.gif" width="320" >

<img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample3.gif" width="320" >
<img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample3.gif" width="320" > <img src="https://github.com/hryk224/IPhotoBrowser/wiki/images/sample4.gif" width="320" >

## Requirements
- iOS 8.0+
Expand Down Expand Up @@ -38,19 +36,25 @@ import IPhotoBrowser
#### initialize

```Swift
convenience init(images: [UIImage], start index:Int)
convenience init(imageUrls: [URL], start index:Int)
convenience init(assets: [PHAsset], start index:Int)
init(images: [UIImage], start index:Int)
init(imageUrls: [URL], start index:Int)
init(assets: [PHAsset], start index:Int)
```

#### IPhotoBrowserDelegate

```Swift
func iPhotoBrowser(_ iPhotoBrowser: IPhotoBrowser, didChange index: Int)

// Present/Dismiss
@objc optional func iPhotoBrowserDidDismissing(_ iPhotoBrowser: IPhotoBrowser)
@objc optional func iPhotoBrowserDidCanceledDismiss(_ iPhotoBrowser: IPhotoBrowser)

// Push/Pop
@objc optional func iPhotoBrowserDidPop(_ iPhotoBrowser: IPhotoBrowser)
@objc optional func iPhotoBrowserDidCanceledPop(_ iPhotoBrowser: IPhotoBrowser)
/// This screenshot is used for pop transitions.
/// Used background image to IPhotoBrowser.
@objc optional func iPhotoBrowserMakeViewScreenshotIfNeeded(_ iPhotoBrowser: IPhotoBrowser) -> UIImage?
```

Expand All @@ -74,6 +78,24 @@ func iPhotoBrowserTransitionWillBegin()
func iPhotoBrowserTransitionDidEnded()
```

#### Entity

`IPhoto`

```Swift
struct IPhoto {
let image: UIImage?
let imageUrl: URL?
let asset: PHAsset?
let title: String?
let description: String?
}
```

```Swift
init(photos: [IPhoto], start index:Int)
```

## Photos from

* by [pakutaso.com](https://www.pakutaso.com/)
Expand Down
66 changes: 66 additions & 0 deletions Sources/IPhoto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// IPhoto.swift
// IPhotoBrowser
//
// Created by hiroyuki yoshida on 2017/02/24.
//
//

import UIKit
import Photos

public struct IPhoto {
public let image: UIImage?
public let imageUrl: URL?
public let asset: PHAsset?
public let title: String?
public let description: String?
var sourceType: IPhotoBrowserSourceType? {
if image != nil {
return .image
} else if imageUrl != nil {
return .imageUrl
} else if asset != nil {
return .asset
}
return nil
}
public init(image: UIImage,
title: String? = nil,
description: String? = nil) {
self.init(image: image,
imageUrl: nil,
asset: nil,
title: title,
description: description)
}
public init(imageUrl: URL,
title: String? = nil,
description: String? = nil) {
self.init(image: nil,
imageUrl: imageUrl,
asset: nil,
title: title,
description: description)
}
public init(asset: PHAsset,
title: String? = nil,
description: String? = nil) {
self.init(image: nil,
imageUrl: nil,
asset: asset,
title: title,
description: description)
}
private init(image: UIImage?,
imageUrl: URL?,
asset: PHAsset?,
title: String?,
description: String?) {
self.image = image
self.imageUrl = imageUrl
self.asset = asset
self.title = title
self.description = description
}
}

0 comments on commit 3ebbfb6

Please sign in to comment.