UIImagePicker Controller in Landscape mode - ios

I have used one UIImagePicker Controller in my game. its working fine in iPad Landscape mode using UIPopOver Controller but as UIPopoverController is not supported in iPhone I have used UIIMagePicker Controller for iPhone.
now, it crashes in my iPhone. please help me.
I have select following Orientation in Deplyoment Info of my project :
Landscape Left
Landscape Right

The UIImagePickerController only support's portrait, so you must make sure your app has portrait as a supported orientation. Please see the UIImagePickerController Class Reference documentation, I have included a quote from the document.
IMPORTANT
The UIImagePickerController class supports portrait mode only. This
class is intended to be used as-is and does not support subclassing.
The view hierarchy for this class is private and must not be modified,
with one exception. You can assign a custom view to the
cameraOverlayView property and use that view to present additional
information or manage the interactions between the camera interface
and your code.
EDIT
Look at the UIApplicationDelegate Protocol, it has the following method
func application(application: UIApplication,
supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
From the documentation:
Discussion
This method returns the total set of interface orientations
supported by the app. When determining whether to rotate a particular
view controller, the orientations returned by this method are
intersected with the orientations supported by the root view
controller or topmost presented view controller. The app and view
controller must agree before the rotation is allowed.
If you do not implement this method, the app uses the values in the
UIInterfaceOrientation key of the app’s Info.plist as the default
interface orientations.

Related

Forcing orientation on a full screen modal doesn't work on parent controller

iOS 16 introduced a new API for forcing orientation changes, which implies using the requestGeometryUpdate(_:errorHandler:).
It seems that it's not working as expected when using a full screen modal.
For example, let's say we have an app that locks the orientation in portrait mode except for a modally presented controller, a parent controller A and a modal controller B :
A is displayed
We put the device in landscape mode - A stays in portrait mode
B is opened modally fullscreen from A
B is displayed in landscape
B has a button to go back to portrait mode using the requestGeometryUpdate(_:errorHandler:)
B is dismissed through a button
A ends up in landscape
In the app delegate, we used supportedInterfaceOrientationsFor to force the app in portait mode except for the controller B.
We tried to call setNeedsUpdateOfSupportedInterfaceOrientations every time we call requestGeometryUpdate(_:errorHandler:).
We also tried to call it on the viewWillAppear from the controller A.
We finally tried to call requestGeometryUpdate(_:errorHandler:) from the controller A's viewWillAppear, without any luck as well.
Is this a bug in iOS 16 or are we missing something ?
It seems to be working as expected when displaying the modal over the current context, but it's not what we want in this case.
I can provide an example project if needed.

How to apply an user interface orientation to an iOS storyboard scene

I am developing an iOS application that allows someone to play one of two different games.
Both games are played in a set of rounds. When a player finishes a round the application transitions to a new scene that displays results and then either transitions to another round scene or an end game scene.
Because of the transient nature of the scenes in the application, it makes little sense to persist scenes as is done in more traditional applications, where someone can return to a previous scene.
To that end, most scene navigation is accomplished by using a UINavigationViewController and simply calling setViewControllers(animated:) supplying an array that contains only the UIViewController for the next scene, and this works quite well.
I mentioned that the application will allow someone to play one of two games. It turns out that, on the iPhone, one game is best played in portrait mode, and the other game works best played in landscape mode. I want to be able to control what user interface orientation is used for a particular UIViewController when it becomes active.
I have experimented with using the supportedInterfaceOrientations property of the UINavigationController and application(_ application: supportedInterfaceOrientationsFor window:) for UIApplicationDelegate, and have been able to get things to work for a standard application. However, when I try to apply things to the way my game application works using setViewControllers(animated:), no methods that pertain to applying the desired user interface orientation seem to get called, and all scenes appear at the same orientation.
What suggestions do people have for how I could get a scene in my application to appear with a particular user interface orientation?
Try making your presented view controller call the following method on it's view will appear, or view did appear:
class func attemptRotationToDeviceOrientation()
Some view controllers may want to use app-specific conditions to
determine what interface orientations are supported. If your view
controller does this, when those conditions change, your app should
call this class method. The system immediately attempts to rotate to
the new orientation.
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621400-attemptrotationtodeviceorientati

Not able to have all orientation for iPad

Hi guys i know this question might be asked before as well , so if u could point out right question to refer to that would be great .
Problem - in my info.plist i have only 2 orientation allowed i.e Portrait ,UpsideDown
and every viewController abides to above orientation .
But for one particular viewController i want whole 360 degree orientation .
this viewController is presented modally with style
UIModelPresentationStyle.FullScreen
And to support all orientation in ViewController ,
i have overridden relevant delegate methods as well
ShouldAutorotate is returning -> Yes ,
PreferredOrientationForPresentation is returning -> UIInterfaceOrientation.LandscapeLeft ;
GetSupportedInterfaceOrientation is returning -> UIINterfaceOrientationMask.all
When this ViewController loads i am getting landscapeLeft as expected , when i rotate the iPad, i get portrait mode as well ,
but now i am not able to return back to landscape mode anymore .
Any reason for that???
in my info.plist i have only 2 orientation allowed
Well, that's the problem. You're doing this wrong. The Info.plist should list every orientation that the app can ever have. Your top-level view controllers can then limit their own orientations.

Is it possible to force orientation in IOS

Is it possible to have a portrait app that contains several different screens, however when the camera in the app is activated it switches to Landscape view and after the camera is done taking the picture returns back to portrait ?
(I want to force the user to only take landscape pictures).
if you read the https://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
you'll find out that the uiimagepickercontroller only supports portrait. here is the part from the class reference.
Important: The UIImagePickerController class supports portrait mode
only. This class is intended to be used as-is and does not support
subclassing. The view hierarchy for this class is private and must not
be modified, with one exception. You can assign a custom view to the
cameraOverlayView property and use that view to present additional
information or manage the interactions between the camera interface
and your code.
the only way would be to create a custom camera overlay method and do it in that method.
if u using some landscape gradient picture for hide the user to take picture in only landscape

How to make UIPopoverController visible at startup in portrait orientation?

I'm making an iPad application using a UISplitViewController. I want the masterView visible in a UIPopoverController when the app starts (and only when it starts) in portrait mode. If I use the presentPopoverFromBarButtonItem:permittedArrowDirections:animated: method in the splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
delegate function, I get the following error, when I start the app in portait mode:
Popovers cannot be presented from a view which does not have a window.
Can anybody help me?
The particular error says that you must add the view to a window before showing the popover, not the other way round. Try sending presentPopover… from the application delegate's -application:didFinishLaunchingWithOptions: after adding the view to your app's window.

Resources