unwanted ios 8 app rotation on certain devices - swift

I'm writing an app in Swift on ios 8 that I want to make sure only works in Portrait mode on all devices (for now). I have "Portrait" selected as the only Device Orientation under "Deployment Info" for the app, as such :
It works fine on simulators and iPhone 6 Plus; however, when testing on an iPad Mini, the orientation changes even though it shouldn't.
Is this a known issue or am I missing a configuration somewhere?
Would love any input. TIA.

Try this:
paste these methods in the ViewController of each view:
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientation.Portrait.rawValue
}
And let me know If it works for you.

Related

AppDelegates function "supportedInterfaceOrientationsFor" does not get called on iPads

In my AppDelegate I am using a function to rotate my device and lock the orientation.
iPhone shall be portrait only, and iPad landscape only.
It works on iPhones, but the following function does never get called on iPads:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
print("Test")
return AppDelegate.orientationLock
}
I think it was working on iPads before I switched to "SwiftUI Life Cicle" but I am not absolutely sure if this was the point of time, where it stopped working:
#UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
The info.plist is also set to "Landscape only" for iPads, but the app starts in portrait mode anyway, which is strange too:
I also faced this issue in iPad, And got solution.
In your Info.Plist make this setting.
or
In your Project > General
I had to set this key in my info.plist to false, so that application(_:supportedInterfaceOrientationsFor:) gets called on iPads:
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
</dict>
Thanks #lorem ipsum for the hint!

Resizing an iOS view with Xamarin.iOS when call status bar is toggled

Is there a trick to detecting when the status bar changes height due to a phone call in Xamarin.iOS?
I'm trying to adapt the excellent instructions from this post to work in Xamarin, and the ChangedStatusBarFrame method is never called.
The following code doesn't do anything in a brand new Xamarin iPhone project:
public virtual void ChangedStatusBarFrame(UIApplication application, RectangleF oldStatusBarFrame)
{
Debug.WriteLine("Y U NO work!");
}
I tried the equivalent in a new native iPhone app and it worked perfectly:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
NSLog(#"Hey, the status bar changed size!");
}
I'm testing this on the iOS simulator by toggling the status bar.
I'm using Xamarin.iOS version 6.4.3.0 and XCode 4.6.3.
Any suggestions?
You should use override keyword:
public override void ChangedStatusBarFrame(UIApplication application, RectangleF oldStatusBarFrame)
{
Debug.WriteLine("Y U NO work!");
}

What are the changes in ios 6 as compare to previous versions of xcode?

I was build an app in ios 4.1 but now i am using ios 6 to build it but there are problems in pushviewcontroller and orientation methods. So can any one tell me what are the changes have brought in ios 6?
I think that best solution is to stick to official apple documentation. So according to that I use following methods and everything is working very well on iOS 5 and 6. In all of your ViewControllers override following methods.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Methods for iOS 6, first method returns supported orientation mask (as their name indicate), you can change it into Landscape or what suites you best.
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ...
}
second one thats tells your VC which is preferred interface orientation when VC is going to be displayed.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ...
}
This solution is working

How can I disable landscape orientation?

I am making an iPhone app and I need it to be in portrait mode, so if the user moves the device sideways, it does not automatically rotate. How can I do this?
To disable orientations for a particular View Controller, you should now override supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation.
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
If you're targeting something older than iOS 6, you want the shouldAutorotateToInterfaceOrientation: method. By changing when it returns yes, you'll determine if it will rotate to said orientation. This will only allow the normal portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
// Use this to allow upside down as well
//return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
Note that shouldAutorotateToInterfaceOrientation: has been deprecated in iOS 6.0.
Xcode 5 and above
Click your project in the Project Navigator in the left sidebar to open the project settings
Go to the General tab.
Uncheck the options you don't want in the Deployment Info section, under Device Orientation
Xcode 4 and below
For those who missed it: you can use the project settings screen to fix orientations throughout the app (no need to override methods in every controller):
It's as simple as toggling the supported interface orientations. You can find by clicking on your Project in the left panel > the app target > Summary tab.
Most simple solution separate for iPhone and iPad (Universal) - its remove unnecessary orientation in the info.plist file or Project -> Info -> Custom iOS Target Properties.
Just add or remove orientation item from list:
Supported interface orientation for iPhone
Supported interface orientations (iPad) for iPad
In Xcode 13.3.1, simply unchecking undesired orientations does not prevent an app from supporting all rotations. It is necessary to enter the Build Settings tab and manually remove any orientations from the following fields that you do not wish to support:
In my case, my app will now only support portrait orientation.
If you want to disable landscape orientation for both iPhone and iPad.
Go to Targets and Go to the General tab. See the below screen and deselect landscape left and landscape right.
Here in this case only iPhone landscape mode will be disabled not for iPad. For iPad all modes are anabled. If you want select device option from Universal to iPad. It will looks like this. See below screen.
Now you need to deselect all modes except Portrait for iPad. See below screenshot.
Now you successfully disabled all modes except Portrait for all devices.
If you created a new Xcode 13.3 project and unchecked unnecessary orientation checkmarks in the Project > General > Deployment and it didn't help. Check the Target > Build Settings - there are 2 rows which override global settings.
Swift 3
If you have a navigationController, subclass it like this (for portrait only):
class CustomNavigationViewController: UINavigationController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return UIInterfaceOrientation.portrait
}
}
Removing the method shouldAutorotateToInterfaceOrientation from your class entirely also works. If you don't plan on rotating then it makes no sense to have the method in your class, the less code the better, keeps things clean.
Xcode 8, Xcode 9, Xcode 10 and above
Also, make changes in Info.plist file
I've had the same problem on Xcode 13.0 even though I set the device orientation only Portrait.
Adding these 2 lines to Info.plist solved my problem.

iPhone app autorotates on one device, but not another

Does anyone know of a reason why an iPhone would autorotate on one device, but not another? I can't reproduce it on my iPhone, iPod Touch, or any of the simulator devices.
Are there any device settings I should be paying attention to? The offending iPhone has the same SDK version installed (4.2.1), but is a different model (MC319LL) than mine (MC605DN).
Well, I never figured out why the two phones were acting differently, but this bit of code in in the UITabBarController subclass seems to have solved things:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
You made sure that the misbehaving device had its rotation lock turned off in the settings, right?