I have an iPad app that should works only at Landscape mode.
But I have to show UIImagePickerController.
According to documentation UIImageController works only with Portrait mode.
If I disabple Portrait orientation and present UIImageViewController I receive crash with
"Supported orientations has no common orientation with the
application, and [PUUIAlbumListViewController shouldAutorotate]”
How I can configure project to disable Portrait mode at iPad and allow to show UIImagePickerController?
My solution without setting Portrait mode
let imagePicker = UIImagePickerController()
imagePicker.modalPresentationStyle = .popover
imagePicker.popoverPresentationController?.sourceView = self.view
imagePicker.sourceType = (UIImagePickerController.isSourceTypeAvailable(.camera)) ? .camera : .photoLibrary
imagePicker.delegate = self
You have no choice. As you have already said, the solution is to enable portrait orientation in your app.
If the intersection between what the view controller requires and what the app permits is null, the app will crash (as you have seen).
Related
I have read a lot on this topic but am not satisfied with my current solution.
I am creating a capture app that is primarily in portrait mode but I would like to force the camera view to be in landscape.
I've been using these simple functions to force the orientation to change in viewWillAppear in my capture view controller.
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = orientation
}
}
static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
self.lockOrientation(orientation)
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
}
One issue is that the view controller still initially visibly loads in portrait and then rotates itself into landscape.
How do I force it to appear in landscape so that it never appears in portrait?
In the future, I may like to use portrait capture as well with behavior much like the default camera app (icons rotate but the capture button and preview remain the same. photos come out in the correct orientation). I'd like to design this interface in the storyboard so I can see both portrait and landscape views in storyboard by changing the device orientation.
How can I make the camera screen handle genuine device orientation change in the storyboard? I have found no clean solutions to doing this.
So I'm working on an iOS 10 app using Swift 3 and Xcode 8.3.3.
In my app I have to take successively 8 pictures with indicators on the camera.
So I'm using AVCaptureVideoPreviewLayer for the custom camera and I need to set the view displaying the camera on landscape mode.
I did it using this extension that I found on stackoverflow while searching for the problem.
struct AppUtility {
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = orientation
}
}
/// OPTIONAL Added method to adjust lock and rotate to the desired orientation
static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
self.lockOrientation(orientation)
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
}
}
and in the viewDidLoad() of the customCameraView, I'm setting the locking the orientation to .landscapeLeft :
AppUtility.lockOrientation(.landscapeLeft)
before leaving the view I'm setting this in my viewWillDissapear method in order to unlock the orientation:
AppUtility.lockOrientation(.all)
The problem is that landscape mode in the customCameraView works only when the auto-rotation of the device is enabled (not locked) and when I get back to the previous view controller, it is initially displayed in landscapeLeft so I have to turn the device to put it portrait mode. this view is locked in portrait method using the AppUtility extension.
So I thought about always activate the auto-rotation by overriding the shouldAutoRotate var but it didn't work when the device auto-rotation is locked.
Then I thought about making sure that the auto-rotation is enabled before opening the camera but 100 of people on stackoverflow are saying that this is not possible.
So the perfect solution for me would be to always make the customCameraView in landscapeLeft mode and the previous view in portrait no matter if the rotate is activated or not.
I'm struggling on this bug for days now and a little help would be great.
iOS encourages developers to support both portrait and landscape, so it can be difficult to restrict one part of the app to be landscape while the other is portrait.
One option that works pretty well is to restrict the entire app to portrait mode in the project settings, and apply a rotation transform to any view controllers that need to be landscape. This way, the view will look and behave like it is landscape, and you have full control over the rotation of your views.
Can you apply below code on the required customCameraView Controller :
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.landscapeLeft
}
I have an issue in one of my applications that I just discovered once I got the app onto an actual iPad, it isn't possible to see in the simulator. The issue is when I hold the iPad in landscape orientation, if I tip the iPad back to a certain angle the iPad stays in landscape mode but the view switches to my portraitView while still in landscape mode. In my code I have a function called screenRotated() that is an observer of UIDeviceOrientationDidChangeNotification. My function screenRotated() has the following code:
let interfaceOrientation: UIDeviceOrientation = UIDevice.currentDevice().orientation
if UIDeviceOrientationIsLandscape(interfaceOrientation) {
//does some stuff and then sets self.view = landscapeView
} else {
//does some stuff and then sets self.view = portraitView
}
How do I keep my app from going into the wrong view when in landscape orientation?
You issue will be that you are not handling device orientation notifications for orientations UIDeviceOrientationFaceUp and UIDeviceOrietationFaceDown. These are neither Portrait or Landscape and your code always picks Portrait when the orientation is not Landscape.
Hence as you are tipping back, it goes to orientation face up and your code picks Portrait as it is not landscape but face up.
So add code to detect faceup/down and ideally keep to the orientation last set until you see it actually go from Portrait to Landscape or the other way around.
The following should work:
if UIDeviceOrientationIsLandscape(interfaceOrientation) {
//does some stuff and then sets self.view = landscapeView
} else if UIDeviceOrientationIsPortrait(interfaceOrientation) {
//does some stuff and then sets self.view = portraitView
}
else{
// Do nothing
}
A heard that is possible to show split view on iPhone in landscape mode on iOS 8? Is it true?
I tried:
let splitViewController = self.window!.rootViewController as UISplitViewController
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
splitViewController.preferredPrimaryColumnWidthFraction = 0.3
Everythings works great but only on iPad. On iPhone I have still full width masterView.
It appears that different documents and discussions indicate that a uiimagepicker should be presented inside a popover, when on an iPad.
Is this really the case or just a suggestion.
I ask as it seems to run perfectly fine in the same VC as the iPhone.
Thanks,
Guy
You can create a UIImagePickerController and add it's View as a subview on any View you like
For example you can add it to a UIViewController
UIImagePickerController imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
View.AddSubview(imagePicker.View);