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

Support rotation #91

Merged
merged 9 commits into from
Jan 19, 2016
Merged

Support rotation #91

merged 9 commits into from
Jan 19, 2016

Conversation

zenangst
Copy link
Contributor

This PR adds rotation support for the CameraView.

It does this by changing the previewLayer.frame.size in viewWillTransitionToSize

Where the magic happens

CameraView.swift

  override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    guard let previewLayer = self.previewLayer,
      connection = previewLayer.connection
      else { return }

    previewLayer.frame.size = size

    switch UIDevice.currentDevice().orientation {
    case .Portrait:
      connection.videoOrientation = .Portrait
    case .LandscapeLeft:
      connection.videoOrientation = .LandscapeRight
    case .LandscapeRight:
      connection.videoOrientation = .LandscapeLeft
    case .PortraitUpsideDown:
      connection.videoOrientation = .PortraitUpsideDown
    default:
      break
    }
  }

Other things fixed

  • Remove duplicate constraint
  • Move .addSubview from lazy methods to viewDidLoad

Screenshots

slack_for_ios_upload_720-2
slack_for_ios_upload_720
slack_for_ios_upload_720-1

@RamonGilabert
Copy link
Contributor

Oh nice. But don't you feel like it should be more like the camera? In terms of rotation. The normal camera when it rotates instead of putting the button at the bottom (which, in my opinion in an iPhone 4 would look bad), they rotate nothing but the views inside the container.

What do you think @vadymmarkov?

@zenangst
Copy link
Contributor Author

Yeah that could be added, I didn't change any of the constraints. Just added support for rotation. We could add that in a different pull request but the iPhone 4 remark is a really good point.

RamonGilabert added a commit that referenced this pull request Jan 19, 2016
@RamonGilabert RamonGilabert merged commit 1512077 into master Jan 19, 2016
@RamonGilabert RamonGilabert deleted the support/rotation branch January 19, 2016 19:12
@vadymmarkov
Copy link
Contributor

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants