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

Fixed issues in iPad landscape #104

Merged
merged 5 commits into from
Feb 14, 2016
Merged
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: objective-c

before_install:
- brew update
#- brew install carthage
- if brew outdated | grep -qx xctool; then brew upgrade xctool; fi

script:
Expand Down
46 changes: 15 additions & 31 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class CameraView: UIViewController {
view.addSubview($0)
}
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
setCorrectOrientationToPreviewLayer()
}

// MARK: - Layout

Expand Down Expand Up @@ -233,21 +238,18 @@ class CameraView: UIViewController {

let queue = dispatch_queue_create("session queue", DISPATCH_QUEUE_SERIAL)

guard let stillImageOutput = self.stillImageOutput else { return }

if let videoOrientation = previewLayer?.connection.videoOrientation {
stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = videoOrientation
stillImageOutput.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = videoOrientation
}

guard let stillImageOutput = self.stillImageOutput else { return }

dispatch_async(queue, { [unowned self] in
stillImageOutput.captureStillImageAsynchronouslyFromConnection(stillImageOutput.connectionWithMediaType(AVMediaTypeVideo),
completionHandler: { (buffer, error) -> Void in
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer)
guard let imageFromData = UIImage(data: imageData) else { return }
let image = self.cropImage(imageFromData)
let orientation = self.pictureOrientation()
guard let imageCG = image.CGImage else { return }
UIImageWriteToSavedPhotosAlbum(UIImage(CGImage: imageCG, scale: 1.0, orientation: orientation), self, "saveImage:error:context:", nil)
UIImageWriteToSavedPhotosAlbum(imageFromData, self, "saveImage:error:context:", nil)
})
})
}
Expand All @@ -256,27 +258,6 @@ class CameraView: UIViewController {
delegate?.imageToLibrary()
}

func cropImage(image: UIImage) -> UIImage {
guard let imageReference = CGImageCreateWithImageInRect(image.CGImage,
CGRect(x: 0, y: 0, width: image.size.height - 285, height: image.size.width)) else { return UIImage() }
let normalizedImage = UIImage(CGImage: imageReference, scale: 1, orientation: .Right)

return normalizedImage
}

func pictureOrientation() -> UIImageOrientation {
switch UIDevice.currentDevice().orientation {
case .LandscapeLeft:
return .Up
case .LandscapeRight:
return .Down
case .PortraitUpsideDown:
return .Left
default:
return .Right
}
}

// MARK: - Timer methods
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway: why was here UIImage() returned instead of the input parameter?


func timerDidFire() {
Expand Down Expand Up @@ -380,12 +361,15 @@ class CameraView: UIViewController {
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

previewLayer?.frame.size = size
setCorrectOrientationToPreviewLayer()
}

func setCorrectOrientationToPreviewLayer() {
guard let previewLayer = self.previewLayer,
connection = previewLayer.connection
else { return }

previewLayer.frame.size = size


switch UIDevice.currentDevice().orientation {
case .Portrait:
connection.videoOrientation = .Portrait
Expand Down
4 changes: 4 additions & 0 deletions Source/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public struct Configuration {
// MARK: Dimensions

public static var cellSpacing: CGFloat = 2

// MARK: Custom behaviour

public static var collapseCollectionViewWhileShot: Bool = true
}
1 change: 1 addition & 0 deletions Source/ImageGallery/ImageGalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class ImageGalleryView: UIView {
collectionView.delegate = self

topSeparator.frame = CGRect(x: 0, y: 0, width: totalWidth, height: Dimensions.galleryBarHeight)
topSeparator.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMargin]
indicator.frame = CGRect(x: (totalWidth - Dimensions.indicatorWidth) / 2, y: (topSeparator.frame.height - Dimensions.indicatorHeight) / 2,
width: Dimensions.indicatorWidth, height: Dimensions.indicatorHeight)
collectionView.frame = CGRect(x: 0, y: topSeparator.frame.height, width: totalWidth, height: collectionFrame - topSeparator.frame.height)
Expand Down
22 changes: 19 additions & 3 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class ImagePickerController: UIViewController {
public weak var delegate: ImagePickerDelegate?
public var stack = ImageStack()
public var imageLimit = 0
let totalSize = UIScreen.mainScreen().bounds.size
var totalSize: CGSize { return UIScreen.mainScreen().bounds.size }
var initialFrame: CGRect?
var initialContentOffset: CGPoint?
var numberOfCells: Int?
Expand Down Expand Up @@ -188,6 +188,15 @@ public class ImagePickerController: UIViewController {

// MARK: - Helpers

public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

let galleryHeight: CGFloat = UIScreen.mainScreen().nativeBounds.height == 960
? ImageGalleryView.Dimensions.galleryBarHeight : GestureConstants.minimumHeight
galleryView.frame = CGRectMake(0, totalSize.height - bottomContainer.frame.height - galleryHeight,
totalSize.width, galleryHeight)
}

public override func prefersStatusBarHidden() -> Bool {
return true
}
Expand Down Expand Up @@ -257,8 +266,15 @@ extension ImagePickerController: BottomContainerViewDelegate {

bottomContainer.pickerButton.enabled = false
bottomContainer.stackView.startLoader()
collapseGalleryView { [unowned self] in
self.cameraController.takePicture()
let action: Void -> Void = { [unowned self] in
self.cameraController.takePicture()
}

if Configuration.collapseCollectionViewWhileShot {
collapseGalleryView(action)
}
else {
action()
}
}

Expand Down