Code Monkey home page Code Monkey logo

skphotobrowser's Introduction

SKPhotoBrowser

Simple PhotoBrowser/Viewer inspired by facebook, twitter photo browsers written by swift

Swift5 Build Status Platform Contributors

features

  • Display one or more images by providing either UIImage objects, or string of URL array.
  • Photos can be zoomed and panned, and optional captions can be displayed
  • Minimalistic Facebook-like interface, swipe up/down to dismiss
  • Ability to custom control. (hide/ show toolbar for controls, / swipe control)
  • Handling and caching photos from web
  • Landscape handling
  • Delete photo support(by offbye). By set displayDelete=true show a delete icon in statusbar, deleted indexes can be obtain from delegate func didDeleted
Table/CollectionView sample Button tap sample gif sample
sample sample sample

Requirements

    - iOS 9.0+
    - Swift 2.0+
    - ARC

Version vs Swift version.

    Below is a table that shows which version of SKPhotoBrowser you should use for your Swift version.
Swift version SKPhotoBrowser version
5.0 >= 6.1.0
4.2 >= 6.0.0
4.1 >= 5.0.0
3.2 >= 4.0.0
2.3 2.0.4 - 3.1.4
2.2 <= 2.0.3

Installation

CocoaPods

available on CocoaPods. Just add the following to your project Podfile:

pod 'SKPhotoBrowser'
use_frameworks!

Carthage

To integrate into your Xcode project using Carthage, specify it in your Cartfile:

github "suzuki-0000/SKPhotoBrowser"

Info.plist

If you want to use share image feature, it includes save image into galery, so you should specify a permission into your Info.plist (if you haven't done it yet).

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Used to save images into your galery</string>

Swift Package Manager

Available in Swift Package Manager. Use the repository URL in Xcode

Usage

See the code snippet below for an example of how to implement, or see the example project.

from UIImages:

// 1. create SKPhoto Array from UIImage
var images = [SKPhoto]()
let photo = SKPhoto.photoWithImage(UIImage())// add some UIImage
images.append(photo)

// 2. create PhotoBrowser Instance, and present from your viewController.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})

from URLs:

// 1. create URL Array
var images = [SKPhoto]()
let photo = SKPhoto.photoWithImageURL("https://placehold.jp/150x150.png")
photo.shouldCachePhotoURLImage = false // you can use image cache by true(NSCache)
images.append(photo)

// 2. create PhotoBrowser Instance, and present.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})

from local files:

// 1. create images from local files
var images = [SKLocalPhoto]()
let photo = SKLocalPhoto.photoWithImageURL("..some_local_path/150x150.png")
images.append(photo)

// 2. create PhotoBrowser Instance, and present.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})

If you want to use zooming effect from an existing view, use another initializer:

// e.g.: some tableView or collectionView.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
   let cell = collectionView.cellForItemAtIndexPath(indexPath)
   let originImage = cell.exampleImageView.image // some image for baseImage

   let browser = SKPhotoBrowser(originImage: originImage ?? UIImage(), photos: images, animatedFromView: cell)
   browser.initializePageIndex(indexPath.row)
   present(browser, animated: true, completion: {})
}

Custom

Toolbar

You can customize Toolbar via SKPhotoBrowserOptions.

SKPhotoBrowserOptions.displayToolbar = false                              // all tool bar will be hidden
SKPhotoBrowserOptions.displayCounterLabel = false                         // counter label will be hidden
SKPhotoBrowserOptions.displayBackAndForwardButton = false                 // back / forward button will be hidden
SKPhotoBrowserOptions.displayAction = false                               // action button will be hidden
SKPhotoBrowserOptions.displayHorizontalScrollIndicator = false            // horizontal scroll bar will be hidden
SKPhotoBrowserOptions.displayVerticalScrollIndicator = false              // vertical scroll bar will be hidden
let browser = SKPhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)

Colors

You can customize text, icon and background colors via SKPhotoBrowserOptions or SKToolbarOptions

SKPhotoBrowserOptions.backgroundColor = UIColor.whiteColor()               // browser view will be white
SKPhotoBrowserOptions.textAndIconColor = UIColor.blackColor()              // text and icons will be black
SKToolbarOptions.textShadowColor = UIColor.clearColor()                    // shadow of toolbar text will be removed
SKToolbarOptions.font = UIFont(name: "Futura", size: 16.0)                 // font of toolbar will be 'Futura'

Images

You can customize the padding of displayed images via SKPhotoBrowserOptions

SKPhotoBrowserOptions.imagePaddingX = 50                                   // image padding left and right will be 25
SKPhotoBrowserOptions.imagePaddingY = 50                                   // image padding top and bottom will be 25

Statusbar

You can customize the visibility of the Statusbar in browser view via SKPhotoBrowserOptions

SKPhotoBrowserOptions.displayStatusbar = false                             // status bar will be hidden

Close And Delete Buttons

That how you can customize close and delete buttons

SKPhotoBrowserOptions.displayDeleteButton = true                           // delete button will be shown
SKPhotoBrowserOptions.swapCloseAndDeleteButtons = true                     // now close button located on right side of screen and delete button is on left side
SKPhotoBrowserOptions.closeAndDeleteButtonPadding = 20                     // set offset from top and from nearest screen edge of close button and delete button

Screenshot Protection

You can protect your image from taking screenshot via SKPhotoBrowserOptions Only working on the device, not on simulator

SKPhotoBrowserOptions.protectScreenshot = true                             // image will be hidden after taking screenshot

Custom Cache From Web URL

You can use SKCacheable protocol if others are adaptable. (SKImageCacheable or SKRequestResponseCacheable)

e.g. SDWebImage

// 1. create custom cache, implement in accordance with the protocol
class CustomImageCache: SKImageCacheable { var cache: SDImageCache }

// 2. replace SKCache instance with custom cache
SKCache.sharedCache.imageCache = CustomImageCache()

CustomButton Image

Close, Delete buttons are able to change image and frame.

browser.updateCloseButton(UIImage())
browser.updateUpdateButton(UIImage())

Delete Photo

You can delete your photo for your own handling. detect button tap from removePhoto delegate function.

Photo Captions

Photo captions can be displayed simply bottom of PhotoBrowser. by setting the caption property on specific photos:

let photo = SKPhoto.photoWithImage(UIImage())
photo.caption = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

SwipeGesture

vertical swipe can enable/disable:

SKPhotoBrowserOptions.disableVerticalSwipe = true

Delegate

There's some trigger point you can handle using delegate. those are optional. See SKPhotoBrowserDelegate for more details.

  • didShowPhotoAtIndex(_ index:Int)
  • willDismissAtPageIndex(_ index:Int)
  • willShowActionSheet(_ photoIndex: Int)
  • didDismissAtPageIndex(_ index:Int)
  • didDismissActionSheetWithButtonIndex(_ buttonIndex: Int, photoIndex: Int)
  • didScrollToIndex(_ index: Int)
  • removePhoto(_ browser: SKPhotoBrowser, index: Int, reload: (() -> Void))
  • viewForPhoto(_ browser: SKPhotoBrowser, index: Int) -> UIView?
  • controlsVisibilityToggled(_ browser: SKPhotoBrowser, hidden: Bool)
let browser = SKPhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
browser.delegate = self

// MARK: - SKPhotoBrowserDelegate
func didShowPhotoAtIndex(_ index: Int) {
// when photo will be shown
}

func willDismissAtPageIndex(_ index: Int) {
// when PhotoBrowser will be dismissed
}

func didDismissAtPageIndex(_ index: Int) {
// when PhotoBrowser did dismissed
}

Options

You can access via SKPhotoBrowserOptions, which can use for browser control. See SKPhotoBrowserOptions for more details.

  • single tap handling, dismiss/noaction
  • blackArea handling which is appearing outside of photo
  • bounce animation when appearing/dismissing
  • text color, font, or more
SKPhotoBrowserOptions.enableZoomBlackArea    = true  // default true
SKPhotoBrowserOptions.enableSingleTapDismiss = true  // default false

Photos from

License

available under the MIT license. See the LICENSE file for more info.

Contributors

Thanks goes to these wonderful people (emoji key):


Oreo Chen

💻

Alexander Khitev

💻

K Rummler

💻

Mads Bjerre

💻

Meng Ye

💻

_ant_one

💻

Tim Roesner

💻

胥冥

💻

Kevin Wolkober

💻

PJ Gray

💻

ghysrc

💻

Josef Doležal

💻

Mark Goody

💻

Philippe Riegert

💻

Bryan Irace

💻

dirtmelon

💻

Heberti Almeida

💻

Felix Weiss

💻

.Some

💻

Onur Var

💻

Andrew Barba

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

skphotobrowser's People

Contributors

alexanderkhitev avatar andrei3pill90 avatar appsunited avatar asolovev avatar ayasutakaohtake avatar barrault01 avatar bigdancemouse avatar dependabot[bot] avatar ghysrc avatar hebertialmeida avatar irace avatar jiacoale avatar jk2k avatar josefdolezal avatar kevinwo avatar krummler avatar lamncn avatar madsb avatar marramgrass avatar onurvar avatar p36348 avatar philipperiegert avatar pj4533 avatar suzuki-0000 avatar timroesner avatar tommyming avatar tparizek avatar vahanmargaryan avatar ysoftware avatar zxming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

skphotobrowser's Issues

Library documentation

Hello team!
Let's comment to the functions, that there will be library documentation?)

How can I update the count when loading more photo after present?

I fetch 10 images per time.

var browser = SKPhotoBrowser()
    override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! GirlCollectionViewCell

        let originImage = cell.ivGirl.image // some image for baseImage
        browser = SKPhotoBrowser(originImage: originImage!, photos: images, animatedFromView: cell)
        browser.delegate = self
        browser.initializePageIndex(indexPath.row)
        presentViewController(browser, animated: true, completion: {})
    }

The browserViewController have shown 10 images, and when I swipe to 10/10 image, I fetch another 10 images in this method:

func didShowPhotoAtIndex(index: Int) {
        print("didShowPhotoAtIndex:\(index)")
        if index + 1 >= self.girlList.count {

            RequestManager.getGirlList(self.index, onSuccess: { (girlList) -> () in
                if girlList.count > 0 {
                    for girl in girlList {
                        let photo = SKPhoto.photoWithImageURL(girl.url)
                        photo.shouldCachePhotoURLImage = false // you can use image cache by true(NSCache)
                        self.images.append(photo)
                    }
                    self.browser.reloadData()
                    self.browser.updateToolbar()
               // ...here's do something else..
                } else {
                    self.collectionView!.mj_footer.endRefreshingWithNoMoreData()
                }
            })
        }

    }

but when I swipe to 10/10 image, the toolNextButton does not enable and the number 10/10 does not update to 10/20.
Please give me some advice.

displayCloseButton has no effects

1、
self.displayCloseButton = false// has no effects
self.enableSingleTapDismiss = true

2、Counld you add a pagecontrol at the bottom?

3、init(originImage: UIImage, photos: [SKPhotoProtocol], animatedFromView: UIView)
should add a similar method originImages: [UIImage], which can be Zoom in originImage?

Wait for you answer...

Delete photo (image)

I saw the delete function. But I want to offer a different resolution. If another developer need a function delete images, it is best to make subclass () and there to override this feature. Since we can not guess where to store the image. I show you my solution

This is in SKPhotoBrowser

public func deleteButtonPressed(sender: UIButton) {

    }

    public func deleteImage() {
        if photos.count > 1 {
            photos.removeAtIndex(currentPageIndex)
            gotoPreviousPage()
            updateToolbar()
        } else if photos.count == 1 {
            dismissPhotoBrowser()
        }
        reloadData()
    }

This is a SKPhotoBrowser subclass

class ImageBrowser: SKPhotoBrowser {

    override func deleteButtonPressed(sender: UIButton) {
        print("ImageBrowser")
        let userDefault = NSUserDefaults.standardUserDefaults()
        let documents = "documents"
        let deleteController = UIAlertController(title: nil, message: "Вы действительно хотите удалить документ?", preferredStyle: .Alert)
        deleteController.addAction(UIAlertAction(title: "Нет", style: .Cancel, handler: nil))
        deleteController.addAction(UIAlertAction(title: "Да", style: .Destructive, handler: { (action) -> Void in
            var allDocuments = [DocumentEntity]()
            if let data = userDefault.objectForKey(documents) as? NSData {
                allDocuments = (NSKeyedUnarchiver.unarchiveObjectWithData(data) as? [DocumentEntity])!
            }
            allDocuments.removeAtIndex(self.currentPageIndex)
            let newData = NSKeyedArchiver.archivedDataWithRootObject(allDocuments)
            userDefault.setObject(newData, forKey: documents)
            userDefault.synchronize()
            self.deleteImage()
        }))
        presentViewController(deleteController, animated: true, completion: nil)
    }
}

And we can to use this subclass like

 let imageBrowser = ImageBrowser(photos: imageArray)
        imageBrowser.delegate = self
        imageBrowser.isForceStatusBarHidden = true
        imageBrowser.displayDeleteButton = true
        imageBrowser.initializePageIndex(indexPath.row)
        presentViewController(imageBrowser, animated: true) { () -> Void in
        }

I checked it and it fine works. What do you think about it?

fatal error: array cannot be bridged from Objective-C

        var images = [SKPhoto]()
        for image in prod.getImages() {
            let photo = SKPhoto.photoWithImageURL(image.fullHdUrl)
            images.append(photo)
        }
        // create PhotoBrowser Instance, and present.
        let browser = SKPhotoBrowser(photos: images)

fatal error: array cannot be bridged from Objective-C
Printing description of browser:
expression produced error: /var/folders/m9/t1ngjfsx4x9fftc2s2_xtt400000gn/T/lldb/62798/expr8.swift:1:46: error: use of undeclared type 'SKPhotoBrowser'
$__lldb__DumpForDebugger(Swift.UnsafePointer<SKPhotoBrowser.SKPhotoBrowser>(bitPattern: 0x134573ac0).memory)
^~~~~~~~~~~~~~
/var/folders/m9/t1ngjfsx4x9fftc2s2_xtt400000gn/T/lldb/62798/expr8.swift:1:45: note: while parsing this '<' as a type parameter bracket
$__lldb__DumpForDebugger(Swift.UnsafePointer<SKPhotoBrowser.SKPhotoBrowser>(bitPattern: 0x134573ac0).memory)

how to disable the

by default, single tap or swipe will let status bar, toolbar and close button disappear.
but if enable single tap dismiss, and use navigationcontroller, when the status bar, toolbar and close button are disappeared, and tap the screen, it will show a statusbar & navigationbar 's height transition, it's ugly.

so i think if single tap dismiss is enabled, dont hide the status bar, toolbar and close button when singtap or swipe

Double tap to zoom doesn't always work

For the images I am using double-tap to zoom just moves the image down a bit, but doesn't zoom in.

I have seen it work in the example application, so I am not sure what is wrong. I'll investigate more and followup here (will submit pull request if i find a solution).

Save pic to phone collection

Is there any possibilities to save picture into phone collection? For example add "save" button or anything else?

Loading more photo after present

Thank you. Nice project.

Can you add a method to load more photos after browser presented.

Something like

browser.appendPhotos([SKPhoto])
browser.reloadData()

Navigation Bar and Bottom Bar

Hi, I need use library with my NavigationController (below Navigation Bar and above my custom Toolbar).
Is any way to do this?

Fatal Error: Array cannot be bridged from Objective-C

I used 1.8.6 , it works fine.
But since I updated to the new version (1.8.8), an error occurred
var skPhotos = [SKPhoto]()
let photoDatas = self.item.photos
do{
for photoData in photoDatas{
let data = try photoData.getData()
skPhotos.append(SKPhoto.photoWithImage(UIImage(data: data)!))
}
}catch{
}
let skPhotoBrowser = SKPhotoBrowser(photos: skPhotos)//Throw that error! Fatal Error: Array cannot be bridged from Objective-C

Error: Array index out of range

Hi,

I have images in my collection view which I get from (Facebook) JSON. If I write self.images.append(SKPhoto.photoWithImage(imageView.image!)), with imageView.image! as my image from JSON data, the Photo Browser works, but it doesn't work properly. For example: when I click on an image, it sometimes shows the next/another image and the displayCounterLabel doesn't give the correct information (the total count is wrong, the count of the selected photo is wrong, it says it's the last photo when there're still photos left).

If I don't write self.images.append(SKPhoto.photoWithImage(imageView.image!)) in my code, when I click a photo, it first seems like it's gonna work, but then soon (when the view isn't completely loaded yet) there's an error, saying: "Array index out of range"...

Can you please help me as soon as possible?

If I have to provide more code or something, please let me know!

Thanks in advance!

didShowPhotoAtIndex delegate

Nice project. Thank you! The didShowPhotoAtIndex delegate is marked as a required. I think it should be marked as optional.

Feature of tap to dismiss?

I really like the feature of swipe to dismiss, but some people are more familiar with single tap to dismiss the browser, maybe just in my country?
Will you guys add this feature? So people can swipe to dismiss, or tap to dismiss, or both.

different supportedInterfaceOrientations for SKPhotoBrowser

Hi,

This is not an issue just a quick question. Is there a way to have the entire project in Portrait and only detect if SKPhotoBrowser is the view and change it to UIInterfaceOrientationMask.All? Something like this:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        super.supportedInterfaceOrientations()
        if presentedViewController?.isKindOfClass(SKPhotoBrowser) != nil {
            return UIInterfaceOrientationMask.All
        } else {
            return UIInterfaceOrientationMask.Portrait
        }
    }

Unfortunately this doesn't work.

This is my info.plist:

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>

Many thanks,

UICollectionView is not working.

I used this library but when I click on an image from the collectionView it does not show the correct image.

and im using the same images as the example.

import UIKit
import SKPhotoBrowser

class PhotoThumbsVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, SKPhotoBrowserDelegate {

@IBOutlet var collectionView: UICollectionView!

var images = [SKPhoto]()

var caption = ["Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
    "It has survived not on/Users/a12556/workspace/_origin/SKPhotoBrowser/README.mdly five centuries, but also the leap into electronic typesetting",
    "remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
    "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
    "It has survived not only five centuries, but also the leap into electronic typesetting",
    "remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
    "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
    "It has survived not only five centuries, but also the leap into electronic typesetting",
    "remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."]


override func viewDidLoad() {
    super.viewDidLoad()

    for i in 0..<30{
        let photo = SKPhoto.photoWithImage(UIImage(named: "image\(i%10).jpg")!)
        photo.caption = caption[i%10]
        images.append(photo)
    }
    setupCollectionView()
    // Do any additional setup after loading the view.
}

private func setupCollectionView (){
    collectionView.delegate = self
    collectionView.dataSource = self
}


 // MARK: - UICollectionViewDataSource

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

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as! CustomThumbsCell

    cell.fotoThumb.image = images[indexPath.row].underlyingImage

    return cell
}



// MARK: - UICollectionViewDelegate

func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! CustomThumbsCell
    let originImage = cell.fotoThumb.image!
    let browser = SKPhotoBrowser(originImage: originImage, photos: images, animatedFromView: cell)
    browser.initializePageIndex(indexPath.row)
    browser.delegate = self
    presentViewController(browser, animated: true, completion: {})
}



// MARK: - SKPhotoBrowserDelegate
func didShowPhotoAtIndex(index: Int) {
    // do some handle if you need
}

func willDismissAtPageIndex(index: Int) {
    // do some handle if you need
}

func didDismissAtPageIndex(index: Int) {
    // do some handle if you need
}

}

class CustomThumbsCell: UICollectionViewCell {

@IBOutlet weak var fotoThumb: UIImageView!


override func awakeFromNib() {
    super.awakeFromNib()
    fotoThumb.image = nil
}

override func prepareForReuse() {
    fotoThumb.image = nil
}

}

Glitch when origin imageview is not correct size

I have a UICollectionViewController subclass where each cell is a UIImageView (similar to your example project). However, my image view's contentMode is set to ScaleAspectFit (because my images may have different sizes). Thus, my sender frame is not the same as my image view's frame.

When I dismiss the SKPhotoBrowser view controller the animation is incorrect, it scales the image to the view's frame, stretching the image, before disappearing.

Bug when zooming small image

Hi! First of all thanks for such control!

There is a bug when trying to zoom a small image with double tap
If you try to zoom such image with gesture everything is fine (it just not scale)

Here is an example
simulator screen shot 30 2016 16 37 07
simulator screen shot 30 2016 16 37 12

URL Pictures are not appearing in CollectionView

Only the first picture is shown as someone clicked on it, but the collection view doesn't show all the pics on it, as it would do if the pics were stored locally (which worked fine, just when I changed to URL they don't appear anymore)

Im using a GET to get the URLs in an array, and then put them in the images array, with the caption and the URL for the picture, and then I set the delegate and data source to self, but they still don't appear.. :(

Crashing when close view before image loaded

if press close button before image was loaded - it leads to crash of the module.
simple solution is:
in file SKPhotoBrowser.swift:
public func performCloseAnimationWithScrollView(scrollView: SKZoomingScrollView) {

change :

 resizableImageView.image = scrollView.photo?.underlyingImage.rotateImageByOrientation() ?? resizableImageView.image 

to:

        if scrollView.photo?.underlyingImage == nil {
            resizableImageView.image = UIImage()
        } else {
        resizableImageView.image = scrollView.photo?.underlyingImage.rotateImageByOrientation() ?? resizableImageView.image 
        }

Custom Cache and ImageDownloader + Floating View

How can I use a custom cache and downloader? I use Kingfisher as my MainImageManager, so when loading a new image from url, both SKPhotoBrowser and Kingfisher downloading the photo.

P.S:
I had one other problem: I have a floating view (like FAB button), when dismissing a photo by swipe, it's animation covers the floating view till it's fit in the source rect. How can I manage this? (I've tried to send the animating view to back of the floating view, but in another view I have two floating buttons that this workaround won't work.)

Also when a photo is dismissed by swipe where source rect is not in view, the animation is weird (flickering till disappears), I've managed it by manipulating the SKPhotoBrowser class, but I just wanted to know do you have any straight solution for that?

Thanks! 😊

Crash on line 884

If the image of collectionview item is not loaded, such as load failed or the web image does not exist, now touch the image that not loaded then close SKPhotoBrower, it will crash on line 884 of SKPhotoBrower.swift.

fatal error: unexpectedly found nil while unwrapping an Optional value

What is wrong

Undefined symbols for architecture arm64:
"protocol descriptor for SKPhotoBrowser.SKPhotoProtocol", referenced from:
type metadata accessor for SKPhotoBrowser.SKPhotoProtocol in GetExtInfoViewController.o
"protocol witness table for SKPhotoBrowser.SKPhoto : SKPhotoBrowser.SKPhotoProtocol in SKPhotoBrowser", referenced from:
MotorCity.GetExtInfoViewController.(viewDidLoad () -> ()).(closure #1).(closure #1).(closure #1).(closure #5).(closure #1).(closure #3) in GetExtInfoViewController.o
MotorCity.TourismInfoViewController.(viewDidLoad () -> ()).(closure #1).(closure #1).(closure #1).(closure #5).(closure #1).(closure #3) in TourismInfoViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Objective-c version

Do you have obj-c version of this lib or may have some plans to make it? Its exactly what i want but its on swift :(

Cannot convert value of type [SKPhotoProtocol] to expected argument type ['AnyObject'] ?

var images = [SKPhotoProtocol]()
            let originImage = cell.portadaImageView.image // some image for baseImage
            let photo = SKPhoto.photoWithImage(originImage!)// add some UIImage
            images.append(photo)
            let browser = SKPhotoBrowser(originImage: originImage!, photos:   images, animatedFromView: cell)
            browser.initializePageIndex(indexPath.row)
            presentViewController(browser, animated: true, completion: {})

This error is in the photos argunment, in the SKPhotoBrowser

Improvement idea for swipe to dismiss

Adding facebook gallery dismiss effect would be nice, photo tracks your finger on x and y, while all ui except photo lose alpha with your movement and you can see view controller which one is behind, and the view controller at behind doesn't show the photo which you are currently holding, just a placeholder. Then when you drop photo it animates to position at behind view controller.

Wrong zoom when touch the black area

Wrong zoom when touch the black area. But I found a solution to the problem. I'm counting on interest clicking on the black area and bear the interest on the image. Also, the image may have a height greater than that of the device in pixels. So I decided to divide the height of the screen into two. Further, if a touch on the black area was in the range of less than half of the screen, Y is equals 0, if more than half of the screen, Y equals image height in pixels. It need to add in SKZoomingScrollView. I hope that it helps you. Thanks

func handleDoubleTap(view: UIView, touch: UITouch) {
        let needPoint = getViewFramePercent(view, touch: touch)
        handleDoubleTap(needPoint)
    }

  private func getViewFramePercent(view: UIView, touch: UITouch) -> CGPoint {
        let oneWidthViewPercent = view.bounds.width / 100
        let viewTouchPoint = touch.locationInView(view)
        let viewWidthTouch = viewTouchPoint.x
        let viewPercentTouch = viewWidthTouch / oneWidthViewPercent

        let photoWidth = photoImageView.bounds.width
        let onePhotoPercent = photoWidth / 100
        let needPoint = viewPercentTouch * onePhotoPercent

        var Y: CGFloat!

        if viewTouchPoint.y < view.bounds.height / 2 {
            Y = 0
        } else {
            Y = photoImageView.bounds.height
        }
        let allPoint = CGPoint(x: needPoint, y: Y)
        return allPoint
    }

SKPhotoBrowser can't be destroied

I use a collectiongView in UItableViewCell.

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

        var images = [SKPhoto]()
        for _url in vo!.photos {
            let photo = SKPhoto.photoWithImageURL(_url)
            photo.shouldCachePhotoURLImage = true // you can use image cache by true(NSCache)
            images.append(photo)
        }


        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! GroupViewCollectionViewCell
        let originImage = cell.imageView.image // some image for baseImage
        let browser = SKPhotoBrowser(originImage: originImage!, photos: images, animatedFromView: cell)
        browser.initializePageIndex(indexPath.row)

        NSNotificationCenter.defaultCenter().postNotificationName("SHOW_PHOTO_BROWER", object: browser)
    }

I handle the notification in tableviewcontroller:

NSNotificationCenter.defaultCenter().addObserver(self, selector:"showPhotoBrower:", name:"SHOW_PHOTO_BROWER", object: nil)

func showPhotoBrower(note:NSNotification){
        weak var browser = note.object as? SKPhotoBrowser
        presentViewController(browser!, animated: true, completion: {})
    }

If I click one collectionviewcell and just close SKPhotoBrowser, it is worked well.
I watch next photo in SKPhotoBrowser then close it, it can not be destory.

SKPhotoBrowser:

deinit {
        pagingScrollView = nil
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

This function can not be reached.
Where do I use the wrong?

Thx ur project.

UIActionSheet & UIPopoverController deprecated

I ported over the action button functionality from IDMPhotoBrowser, but didn't realize they were using deprecated code. I'll update & submit a pull request to get rid of the warnings.

swipe horizontal bug

when button hidden, horizontal swipe sometime not working. bug happens when swiping to the last photo.

trouble when rotating device

Hello! I have strange bug on my project and on your example. When rotating device image do not sizing on all screen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.