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

Swift5 and iPhone X fix #293

Open
wants to merge 17 commits into
base: ajijoyo-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
2 changes: 1 addition & 1 deletion Fusuma.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Fusuma"
s.version = "1.3.0"
s.version = "1.3.3"
s.summary = "Instagram-like photo browser with a few line of code written in Swift"
s.homepage = "https://github.com/ytakzk/Fusuma"
s.license = 'MIT'
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# NOTE: This project is no longer maintained.

We highly recommend [YPImagePicker](https://github.com/Yummypets/YPImagePicker).

## Fusuma

Fusuma is a Swift library that provides an Instagram-like photo browser with a camera feature using only a few lines of code.
Expand Down Expand Up @@ -43,26 +47,27 @@ pod 'Fusuma'
```

#### Swift 3
The latest version does support Swift 4.2. If you're still using Swift 3, you can install Fusuma as follows:

`pod 'Fusuma', github: 'git@github.com:ytakzk/Fusuma.git', branch: 'swift-3'`
`pod 'Fusuma', git: 'git@github.com:ytakzk/Fusuma.git', branch: 'swift-3'`

## Fusuma Usage
Import Fusuma ```import Fusuma``` then use the following codes in some function except for viewDidLoad and give FusumaDelegate to the view controller.

```Swift
let fusuma = FusumaViewController()
fusuma.delegate = self
fusuma.hasVideo = true //To allow for video capturing with .library and .camera available by default
fusuma.availableModes = [FusumaMode.library, FusumaMode.camera, FusumaMode.video] // Add .video capturing mode to the default .library and .camera modes
fusuma.cropHeightRatio = 0.6 // Height-to-width ratio. The default value is 1, which means a squared-size photo.
fusuma.allowMultipleSelection = true // You can select multiple photos from the camera roll. The default value is false.
self.presentViewController(fusuma, animated: true, completion: nil)
self.present(fusuma, animated: true, completion: nil)
```

#### Delegate methods

```Swift
// Return the image which is selected from camera roll or is taken via the camera.
func fusumaImageSelected(image: UIImage, source: FusumaMode) {
func fusumaImageSelected(_ image: UIImage, source: FusumaMode) {

print("Image selected")
}
Expand All @@ -73,7 +78,7 @@ func fusumaDismissedWithImage(image: UIImage, source: FusumaMode) {
print("Called just after FusumaViewController is dismissed.")
}

func fusumaVideoCompleted(withFileURL fileURL: NSURL) {
func fusumaVideoCompleted(withFileURL fileURL: URL) {

print("Called just after a video has been selected.")
}
Expand All @@ -85,7 +90,7 @@ func fusumaCameraRollUnauthorized() {
}

// Return selected images when you allow to select multiple photos.
func fusumaMultipleImageSelected(images: [UIImage], source: FusumaMode) {
func fusumaMultipleImageSelected(_ images: [UIImage], source: FusumaMode) {

}

Expand All @@ -105,7 +110,7 @@ fusumaCameraRollTitle = "CustomizeCameraRollTitle"
fusumaCameraTitle = "CustomizeCameraTitle" // Camera Title
fusumaTintColor: UIColor // tint color
// ...
self.presentViewController(fusuma, animated: true, completion: nil)
self.present(fusuma, animated: true, completion: nil)

```

Expand Down
7 changes: 4 additions & 3 deletions Sources/FSCameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ final class FSCameraView: UIView, UIGestureRecognizerDelegate {
}

DispatchQueue.global(qos: .default).async(execute: { () -> Void in
let videoConnection = imageOutput.connection(with: AVMediaType.video)
guard let videoConnection = imageOutput.connection(with: AVMediaType.video) else { return }

imageOutput.captureStillImageAsynchronously(from: videoConnection!) { (buffer, error) -> Void in
imageOutput.captureStillImageAsynchronously(from: videoConnection) { (buffer, error) -> Void in
self.stopCamera()

guard let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer!),
guard let buffer = buffer,
let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer),
let image = UIImage(data: data),
let cgImage = image.cgImage,
let delegate = self.delegate,
Expand Down
46 changes: 21 additions & 25 deletions Sources/FusumaViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,33 +257,29 @@ public struct ImageMetadata {
libraryButton.removeFromSuperview()
cameraButton.removeFromSuperview()
videoButton.removeFromSuperview()

return
}

if !availableModes.contains(.camera) {
return
}

if fusumaCropImage {
let heightRatio = getCropHeightRatio()
cameraView.croppedAspectRatioConstraint = NSLayoutConstraint(
item: cameraView.previewViewContainer,
attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: cameraView.previewViewContainer,
attribute: NSLayoutConstraint.Attribute.width,
multiplier: heightRatio,
constant: 0)

cameraView.fullAspectRatioConstraint.isActive = false
cameraView.croppedAspectRatioConstraint?.isActive = true

} else {
cameraView.fullAspectRatioConstraint.isActive = true
cameraView.croppedAspectRatioConstraint?.isActive = false

if availableModes.contains(.camera) {
if fusumaCropImage {
let heightRatio = getCropHeightRatio()
cameraView.croppedAspectRatioConstraint = NSLayoutConstraint(
item: cameraView.previewViewContainer,
attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: cameraView.previewViewContainer,
attribute: NSLayoutConstraint.Attribute.width,
multiplier: heightRatio,
constant: 0)

cameraView.fullAspectRatioConstraint.isActive = false
cameraView.croppedAspectRatioConstraint?.isActive = true

} else {
cameraView.fullAspectRatioConstraint.isActive = true
cameraView.croppedAspectRatioConstraint?.isActive = false
}
cameraView.initialCaptureDevicePosition = cameraPosition
}
cameraView.initialCaptureDevicePosition = cameraPosition

doneButton.isEnabled = false
}
Expand Down