add SKLocalPhoto to support local photo from file
This commit is contained in:
parent
9d925c80cc
commit
1a05d44f2d
|
|
@ -18,6 +18,7 @@
|
|||
8909B5491BC791510060A053 /* SKPhotoBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B5411BC791510060A053 /* SKPhotoBrowser.swift */; };
|
||||
8909B54A1BC791510060A053 /* SKZoomingScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B5421BC791510060A053 /* SKZoomingScrollView.swift */; };
|
||||
8909B54D1BC7916E0060A053 /* SKPhotoBrowser.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8909B54C1BC7916E0060A053 /* SKPhotoBrowser.bundle */; };
|
||||
8CA6C6521CBE76E80054D3C2 /* SKLocalPhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CA6C6511CBE76E80054D3C2 /* SKLocalPhoto.swift */; };
|
||||
A64B89361CB04222000071B9 /* SKPhotoBrowserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A64B89351CB04222000071B9 /* SKPhotoBrowserTests.swift */; };
|
||||
A64B89381CB04222000071B9 /* SKPhotoBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5301BC791280060A053 /* SKPhotoBrowser.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
|
@ -46,6 +47,7 @@
|
|||
8909B5411BC791510060A053 /* SKPhotoBrowser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SKPhotoBrowser.swift; sourceTree = "<group>"; };
|
||||
8909B5421BC791510060A053 /* SKZoomingScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SKZoomingScrollView.swift; sourceTree = "<group>"; };
|
||||
8909B54C1BC7916E0060A053 /* SKPhotoBrowser.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = SKPhotoBrowser.bundle; sourceTree = "<group>"; };
|
||||
8CA6C6511CBE76E80054D3C2 /* SKLocalPhoto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SKLocalPhoto.swift; sourceTree = "<group>"; };
|
||||
A64B89331CB04222000071B9 /* SKPhotoBrowserTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SKPhotoBrowserTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A64B89351CB04222000071B9 /* SKPhotoBrowserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SKPhotoBrowserTests.swift; sourceTree = "<group>"; };
|
||||
A64B89371CB04222000071B9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
|
@ -105,6 +107,7 @@
|
|||
8909B53D1BC791510060A053 /* SKDetectingView.swift */,
|
||||
8909B53E1BC791510060A053 /* SKIndicatorView.swift */,
|
||||
8909B53F1BC791510060A053 /* SKPhoto.swift */,
|
||||
8CA6C6511CBE76E80054D3C2 /* SKLocalPhoto.swift */,
|
||||
8909B5411BC791510060A053 /* SKPhotoBrowser.swift */,
|
||||
8909B5421BC791510060A053 /* SKZoomingScrollView.swift */,
|
||||
8909B5331BC791280060A053 /* SKPhotoBrowser.h */,
|
||||
|
|
@ -252,6 +255,7 @@
|
|||
files = (
|
||||
8909B5441BC791510060A053 /* SKDetectingImageView.swift in Sources */,
|
||||
8909B54A1BC791510060A053 /* SKZoomingScrollView.swift in Sources */,
|
||||
8CA6C6521CBE76E80054D3C2 /* SKLocalPhoto.swift in Sources */,
|
||||
210E53ED1C986D3A008DD5E3 /* UIView+Radius.swift in Sources */,
|
||||
8909B5471BC791510060A053 /* SKPhoto.swift in Sources */,
|
||||
8909B5461BC791510060A053 /* SKIndicatorView.swift in Sources */,
|
||||
|
|
@ -459,6 +463,7 @@
|
|||
A64B893C1CB04222000071B9 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// SKLocalPhoto.swift
|
||||
// SKPhotoBrowser
|
||||
//
|
||||
// Created by Antoine Barrault on 13/04/2016.
|
||||
// Copyright © 2016 suzuki_keishi. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
// MARK: - SKLocalPhoto
|
||||
public class SKLocalPhoto: NSObject, SKPhotoProtocol {
|
||||
|
||||
public var underlyingImage: UIImage!
|
||||
public var photoURL: String!
|
||||
public var shouldCachePhotoURLImage: Bool = false
|
||||
public var caption: String!
|
||||
public var index: Int?
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
convenience init(url: String) {
|
||||
self.init()
|
||||
photoURL = url
|
||||
}
|
||||
|
||||
convenience init(url: String, holder: UIImage?) {
|
||||
self.init()
|
||||
photoURL = url
|
||||
underlyingImage = holder
|
||||
}
|
||||
|
||||
public func checkCache() {}
|
||||
|
||||
public func loadUnderlyingImageAndNotify() {
|
||||
|
||||
if underlyingImage != nil && photoURL == nil {
|
||||
loadUnderlyingImageComplete()
|
||||
}
|
||||
|
||||
if photoURL != nil {
|
||||
// Fetch Image
|
||||
if NSFileManager.defaultManager().fileExistsAtPath(photoURL) {
|
||||
if let data = NSFileManager.defaultManager().contentsAtPath(photoURL) {
|
||||
self.loadUnderlyingImageComplete()
|
||||
if let image = UIImage(data: data) {
|
||||
self.underlyingImage = image
|
||||
self.loadUnderlyingImageComplete()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func loadUnderlyingImageComplete() {
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(SKPHOTO_LOADING_DID_END_NOTIFICATION, object: self)
|
||||
}
|
||||
|
||||
// MARK: - class func
|
||||
public class func photoWithImageURL(url: String) -> SKLocalPhoto {
|
||||
return SKLocalPhoto(url: url)
|
||||
}
|
||||
|
||||
public class func photoWithImageURL(url: String, holder: UIImage?) -> SKLocalPhoto {
|
||||
return SKLocalPhoto(url: url, holder: holder)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue