GithubHelp home page GithubHelp logo

lbrndnr / imagepickersheetcontroller Goto Github PK

View Code? Open in Web Editor NEW
1.4K 36.0 211.0 17.7 MB

ImagePickerSheetController replicates the custom photo action sheet in iMessage.

Home Page: http://laurinbrandner.ch

License: MIT License

Swift 92.56% Ruby 6.88% Objective-C 0.55%

imagepickersheetcontroller's Introduction

ImagePickerSheetController

Twitter: @lbrndnr License Carthage compatible

About

ImagePickerSheetController is a component that replicates the custom photo action sheet in iMessage. It's very similar to UIAlertController which makes its usage simple and concise. ⚠️You can also find an iOS 10 version of this library here⚠️

Screenshot

Usage

ImagePickerSheetController is similar to UIAlertController in its usage.

Example

let controller = ImagePickerSheetController(mediaType: .ImageAndVideo)
controller.addAction(ImagePickerAction(title: NSLocalizedString("Take Photo Or Video", comment: "Action Title"), secondaryTitle: NSLocalizedString("Add comment", comment: "Action Title"), handler: { _ in
	presentImagePickerController(.Camera)
}, secondaryHandler: { _, numberOfPhotos in
	println("Comment \(numberOfPhotos) photos")
}))
controller.addAction(ImagePickerAction(title: NSLocalizedString("Photo Library", comment: "Action Title"), secondaryTitle: { NSString.localizedStringWithFormat(NSLocalizedString("ImagePickerSheet.button1.Send %lu Photo", comment: "Action Title"), $0) as String}, handler: { _ in
	presentImagePickerController(.PhotoLibrary)
}, secondaryHandler: { _, numberOfPhotos in
	println("Send \(controller.selectedImageAssets)")
}))
controller.addAction(ImagePickerAction(title: NSLocalizedString("Cancel", comment: "Action Title"), style: .Cancel, handler: { _ in
	println("Cancelled")
}))
            
presentViewController(controller, animated: true, completion: nil)

It's recommended to use stringsdict to easily translate plural forms in any language.

Installation

CocoaPods

pod "ImagePickerSheetController", "~> 0.9.1"

###Carthage

github "lbrndnr/ImagePickerSheetController" ~> 0.9.1

You should also add two new values to your app's Info.plist to tell the user why you need to access the Camera and Photo Library.

<key>NSCameraUsageDescription</key>
<string>Camera usage description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo Library usage description</string>

Requirements

ImagePickerSheetController is written in Swift and links against Photos.framework. It therefore requires iOS 9.0 or later.

Author

I'm Laurin Brandner, I'm on Twitter.

License

ImagePickerSheetController is licensed under the MIT License.

imagepickersheetcontroller's People

Contributors

ashishgarud03 avatar balestrapatrick avatar colinta avatar garudashish avatar lbrndnr avatar liangxianzhe avatar retval avatar vinnyt avatar xbeg9 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

imagepickersheetcontroller's Issues

Error on integrating IPSC with carthage

I'm trying to integrate IPSC with carthage. However the building process of IPSC involves all testing stuffs including Nimble/Quick/KIF and fails eventually when trying to build Quick. I suppose apps link against IPSC should not rely on its unit tests.

Crashing with iOS 9

I installed iOS 9 on an iPhone 6 and the library is don't working anymore.
Indeed if you tab on any pictures inside the collection view to select one it crashes with the following error :

2015-06-09 23:05:04.010 barter[592:608643] *** Assertion failure in -[UICollectionViewData validateLayoutInRect:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3473.13/UICollectionViewData.m:408
2015-06-09 23:05:04.015 barter[592:608643] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) changed from <UICollectionViewLayoutAttributes: 0x135b39780> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (73 5; 29 130); hidden = YES; zIndex = 1;  to <UICollectionViewLayoutAttributes: 0x135c32f00> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (73 5; 29 233); hidden = YES; zIndex = 1;  without invalidating the layout'
*** First throw call stack:

However I fixed the issue in the didSelectItemAtIndexPath method of the library more precisely inside the animateWithDuration block by adding * layout.showsSupplementaryViews = true* between the tableview updates methods.

                self.setNeedsLayout()
                UIView.animateWithDuration(enlargementAnimationDuration, animations: {
                    self.tableView.beginUpdates()
                    layout.showsSupplementaryViews = true
                    self.tableView.endUpdates()
                    self.layoutIfNeeded()
                    }, completion: { finished in
                        self.reloadButtonTitles()
                        layout.showsSupplementaryViews = true
                        self.delegate?.imagePickerSheetDidEnlargePreviews?(self)
                })

It is maybe not a real fix because ios9 is under beta. Moreover the fixe appears to make the collectionview scrolling at the beginning so the selected picture will not be at the center of the collection view.
But it can still help someone who is facing the same issue.

Frameworks not imported

Hi,

I downloaded it through Carthage, imported the ImagePickerSheetController in Build Phases, and copied the swift files with the classes in it, but Xcode doesn't find the XCTest, Nimble,... So I thought I needed to import them, but I can't seem to find them in the Carthage build. Am I doing this the totally wrong way?
Awesome ImagePicker design!
Thanks

Resizing edited images

I'm not sure what's the problem (maybe it's my app, but you can check that if you want :), after editing image in iphone library I can't get original size of the image (if I choose it from image picker). But if I choose edited image from Photo Library everything is fine. I took some screenshots from my app, Second photo is original photo picked from picker, fourth photo is edited (picked from picker, too), and fifth is same edited photo picked from Photo Library -> Camera Roll.

01

02

03

04

05

building with Carthage

I am trying to use carthage to get this into a project. It fails to build with the following:

=== BUILD TARGET BRNImagePickerSheet OF PROJECT BRNImagePickerSheet WITH CONFIGURATION Release ===

Check dependencies
Code Sign error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) matching the team ID “XXXXXXXXXX” were found.
CodeSign error: code signing is required for product type 'Framework' in SDK 'iOS 8.2'

I just started giving carthage a go so it could be something I am doing wrong. Any thoughts?

Could not load 'burst mode' photos

There is a problem with 'burst mode' photos, if you have those kind of photos in library, app crashes.
It's not a problem for my app currently, I can skip those photos, so I just checking if photo is in burst mode in fetchAssets() method, and don't append them to assets, but that's suggestion if you want to show these. My 'solution':

private func fetchAssets() {
......
let result = PHAsset.fetchAssetsWithMediaType(.Image, options: options)
result.enumerateObjectsUsingBlock { obj, _, _ in
if let asset = obj as> PHAsset {
if(asset.burstIdentifier == nil){
self.assets.append(asset)
}
}
}
}

select photo cause crash when camera roll has only 1-3 images on iOS 9

I run the demo in the project, when camera roll has very few photo, select will cause crash on iOS 9, iPhone 6s
Here is the crash log and call stack
2015-10-10 14:48:19.865 Example[37983:1364492] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) changed from <UICollectionViewLayoutAttributes: 0x7f874a7708d0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (46.7011 5; 47 119); hidden = YES; zIndex = 1; to <UICollectionViewLayoutAttributes: 0x7f874a45f6d0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (46.7011 5; 47 271); hidden = YES; zIndex = 1; without invalidating the layout'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109be5f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010b9a4deb objc_exception_throw + 48
2 CoreFoundation 0x0000000109be5dca +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010a02eae2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 UIKit 0x000000010ad8cafd __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 921
5 UIKit 0x000000010ad8c240 -[UICollectionViewData validateLayoutInRect:] + 3067
6 UIKit 0x000000010ad3c83e -[UICollectionView layoutSubviews] + 196
7 UIKit 0x000000010a5dd11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
8 QuartzCore 0x000000010c71036a -[CALayer layoutSublayers] + 146
9 QuartzCore 0x000000010c704bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366

Get image from slider

When the user takes a photo manually, the didFinishPickingWithOptions (or something really similar) method gets called so you can get the image from there. This also works when manually selecting from Photo Library. The problem I'm encountering it when using the slider to pick an image and click send, I can't get the image file. I can use controller.selectedImageAssets but it's a [phasset] file.

How am I actually able to get a UIImage from the slider? I'm using the example code.

Thanks for your help, really like the layout of the custom picker!

KIF tests

In order to test the component thoroughly, KIF tests need to be written. Help would be appreciated :)

Memory Issues

Using the latest version when I run on my 5s and select 11 or more photos from my camera roll the app uses too much memory and crashes. Can the images be returned as reference, or can you return indexes in getSelectedImagesWithCompletion() and we can grab the high quality version and process it one at a time.

Thanks.


2015-07-03 14:33:37.217 Example[15609:4906189] Connection to assetsd was interrupted or assetsd died
2015-07-03 14:33:37.623 Example[15609:4906072] Received memory warning.
2015-07-03 14:33:37.895 Example[15609:4906072] Received memory warning.

Crashing on iphone 5s

It works great in the simulator but when ran on my phone it crashes. I'm running ios 8.1.1 on a 5s. To be sure it was not my implementation, I used your code sample to test.

Obj-C

Hello and thanks for this lib. :)
Is there any change this can be ported to Obj-C?

thanks

Optimize masking

  • Don't show separators when not necessary
  • Don't mask on iOS 8, no masking layer

iPhone 6 (iOS 8) CheckMark Position Issue

Seems to be an issue with the bottom right circle being a little bit off to the right. I copy and pasted the code as is in my swift class. My xib file is using auto layout.
ios simulator screen shot jun 15 2015 10 55 20 am
ios simulator screen shot jun 15 2015 10 55 25 am
ios simulator screen shot jun 15 2015 10 55 29 am

Remove "Add Comment"

In many situations, "Add Comment" is not necessary. How can i remove it? Or can someone share a version without it?

Could not obtain unique identifier for attached screen

2015-03-16 01:16:38.893 Example[1186:217454] Could not obtain unique identifier for attached screen <UIScreen: 0x1755fd90; bounds = {{0, 0}, {768, 576}}; mode = <UIScreenMode: 0x17662db0; size = 720.000000 x 576.000000; pixel aspect ratio = 1.092593>>

Add types to SecondaryHandler

Can you add type of selected media to SecondaryHandler?
I want to show title like in iMessage -> 1 Video, 1 Photo or 2 objects.

PHPhotoLibrary Authorization

ImagePickerSheetController should be requesting the PHPhotoLibrary access by itself, to make it easier to use.

CompileAssetsCatalog fails randomly

I get an error very randomly when trying to compile the asset catalog...

I don't seem to get any more information than this. Most of the time it passes compilation sometimes it fails...

The following build commands failed:
    CompileAssetCatalog /Users/greenhouse/tmp4ZakUq/build/Debug-iphoneos/ImagePickerSheetController.framework ImagePickerSheetController/ImagePickerSheetController/ImagePickerSheetController/Images.xcassets
(1 failure)


Build failed :|
Running xcodebuild failed```

Scrolling not smooth at all on iPhone 5.

So the problem on my end is that when I tested the example on iPhone 5, iOS 8.3 the scrolling, between the images, was not smooth at all. In iMessage is very smooth.

Thank you!

Update documentation, pod version

The documentation is 0.1.7

But it should be 0.9 to reflect the most updated version.

Also sample code isn't correct in comparison with master's example code.

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.