Is it possible to force orientation in IOS - 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

Related

Autorotate Portrait mode documents if it is showing as landscape

In my app user scans(captures photos of) documents. For uploading to the server.
I want to programmatically detect the document's orientation.
It looks like this.
And then user tap that circular arrow button and make it portrait.
Then it looks like this
I want to do this rotation task automatically.
Please let me know how we can do this, I never came across this kind of requirement.

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

UIImagePicker Controller in Landscape mode

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.

Unity iOs - screen gets black when changing rotation while Unity is paused

I have a unity app, that uses Vuforia AR library. I extended this app with some iOs code. I wanted to be able to display my custom UIViewControllers sometimes instead of the main view controller that Unity uses. But I want to be able to switch back. I.e: I have a button that opens UIViewController with "About app" information and this controller then has "Exit" button to return to Unity controller.
This is my code for adding the new controller instead of the Unity View Controller:
self.unityRootController = self.keyWindow.rootViewController; // keep reference to the Unity Controller
self.keyWindow.rootViewController = controller; // display my own controller
// this pauses the unity and qcar -> so that QCAR doesn't try to recognize objects, when Unity Controller is not up
QCARUnityPlayer::getInstance().QCARPause(true);
UnityPause(true);
Then when returning from my own controller to Unity controller:
self.keyWindow.rootViewController = self.unityRootController; // return to Unity Controller
// start tracking with QCAR and unpause Unity View
QCARUnityPlayer::getInstance().QCARPause(false);
UnityPause(NO);
This works fine except one case, that's caused me to pull my hair ever since encountering it. My app supports changing orientation of screen in both Unity and ObjectiveC code. And this is the trouble: If I open my View Controller while the device is for example in Portrait Orientation, then turn the device to Landscape orientation, my controller gets correctly rotated. But if I at this moment want to close my custom view controller and return to unity controller, the screen gets black suddenly. After rotating the device to portrait orientation, the unity controller suddenly starts working as expected.
I'd like the unity controller to start directly after closing my custom view controller even if the screen orientation is changed. I suppose I have to add some code after I start again the Unity Player here:
QCARUnityPlayer::getInstance().QCARPause(false);
UnityPause(NO);
// TODO: supposedly some code should go here, that fixes black screen
But I tried to find something in the AppController.mm, that is builded by Unity and I could not find anything, that would help me. I found few lines of unity code, that had the word "orientation" in it, but I tried to use that code and didn't help. Does anybody know, what should I do, please? Thanks a bunch :)
Not sure if you have fixed this, Its been a while... But the reason that your UnityViewController is not functioning properly is because a view controller that is not visible will not receive rotation events. Because you are setting your view controller as the root view controller, the UnityDefaultViewController defined in "iPhone_View.mm" is not receiving rotation events.
I have been studying Unity's rotation for a while now as I have my own issue with a similar setup.
There are a few things that you might be able to try:
In iPhone_View.mm there is a function that is defined called: UpdateOrientationFromController(UIViewController* controller) that might be able to solve your problem. You would want to call this function on the view controller that you designed yourself where you placed your //TODO comment. That function calls a few key functions and methods that handle Unity's interface orientations:
ConvertToUnityScreenOrientation: for some reason Unity Uses their own defined screen orientations, this internally converts the orientation to what Unity uses.
QCARUnityPlayer::getInstance().QCARSetOrientation(): QCAR Also needs its orientation to be set
UnitySetScreenOrientation(_curOrientation): The unity library has an internal way of checking the screen orientation at every rendered frame. I think this function sets an internal flag for the Unity View to check in CheckOrientationRequest() defined in iPhone_View.h as well.
AppController_RenderPluginMethodWithArg is called, I am not sure what this does, but I think it does something important
OrientTo(_curOrientation): this kicks off the actual orientation change and handles the right calls. This includes the call to AppController's onForcedOrientation: method that does the final orientation.
You may be able to call AppController's onForcedOrientation: method directly with a UnityScreenOrientation after you convert a UIDeviceOrientation to a UnityScreen Orientation with ConvertToUnityScreenOrientation() defined in iPhone_OrientationSupport.h. You may not want to call this method directly though, because there are quite a few things that are involved with Unity's orientation methods. You would do this when your app returns from presenting your view controller.
The last thing, and the "hackiest thing" that you can do, that will get the job done, but not in the most efficient way, is to add UnityDefaultViewController to your ViewController as a child ViewController with the addChildViewController: UIViewController Docs, or maybe as just a property, and then override the willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:in your ViewController and after calling super, pass the message to the UnityDefaultViewController. This will cause the UnityDefaultViewController to update the UnityView every time the orientation changes, even though the view isn't actually visible. You may or may not need to unpause Unity in order for this to function.
Of the three methods, the last one should definitely work, because I have implemented it myself. However, the first one should work as well, because Unity uses it several times to check the devices current orientation from the splash screen.
Hope this helps!

iPad forces portrait mode when touching 'Take Photo or Video'

I've built an HTML5 iPad web app in landscape mode, now I'm to the point I need to let the user add an image either from taking an image or choosing one from the camera roll.
Here's the problem:
The iPad is locked in landscape mode, user touches my button: 'Add Photo' Apple menu alerts: 'Take Photo or Video' or 'Choose Existing' User touches 'Take Photo or Video'.
When the Camera slides over and opens up the web app goes into portait mode!, and after the user takes the image or even cancels out of taking an image my web app is stuck in portrait mode and will not go back into landscape until you unlock the iPad, turn to portrait then back to landscape!!
Note: if the user selects 'Choose Existing' and uploads from the camera roll there is no issue.
Is there anything I can do? Is there a way to not provide the 'Take Photo or Video' option and only allow the 'Choose Existing' option?
Thank you in advance!
I've run into a similar problem. In my case the camera roll is only showing in portrait mode on my iPad which I'm using in landscape. After looking through the API reference it looks like this is by design:
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.
UIImagePickerController Reference

Resources