sencha touch :: how to supress orientation change - iphone

In my sencha-tpuch / phonegap app on iOS I want my app not to change orientation with the device its used on. how could I suppress orientation change in sencha-touch or what would I override exactly?
thnx!

You dont need to edit any code. All you need to do is go to your configuration files and specify orientations you want to support. By default all 4 orientations are supported, you have to edit it to support orientations you want. Rebuild the application and Go.
The entry should be in one of the following files:
phonegap.plist/application.plist/config.xml
Also check this link.
With only Sencha Touch, as it cannot force browser not to change orientation, it is NOT possible to remove orientation change. See this link.

In your phonegap xcode project find the file MainViewController.m in there find the function
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
And return yes for supported orientations.

Related

set cocos2-x project to portrait orientation

I am trying to set up my project with portrait orientation, but I am just getting landscape. I am using cocos2d-x (2.1.4).
I have set, as said here:
At RootViewController.mm:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskPortrait;
#endif
}
I also tried changing the settings, still nothig.
setDeviceOrientation does not exist anymore...
Anyone knows how I can set the project to portrait??
UPDATE: It seems to work on the device, it only happens on the simulator
I do it this way: In xcode at the top of the file list is the project. Go to that, then the "Targets > whatever" bit. You have "supported Interface orientations". You can check off which orientations you want and don't want. Make sure to note that there are 2 different sections for iPhone and iPad, you'll have to scroll down and set it separately in the iPad orientation section.
I'd imagine the reason it doesn't work in the simulator is that you're using an iPhone/iPod for testing and running the iPad simulator.

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.

Autorotation doesn't work

I have a code in each view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
also I changed supported device orientations in a plist.
What else could it be?
P.S. As I checked — notifications about rotation not sends anymore. Probably there is a conflict with some framework...
Check this out Why won't my UIViewController rotate with the device?
And one remark, do not modify device orientations from plist, there is another way , select project , then Summary tab and then in Supported Device Orientations choose that you need. This way will automatically edit your plist.

how to lock/unlock orientation lock of iphone programmatically?

we know that these simple steps to lock/unlock the orientation of your iPhone 3G:
From any screen, double-tap the home button
Scroll as far left as you can on the multitasking dock
The first symbol to the left will be a circular arrow
Select this to either lock or unlock the orientation of your iPhone 3G
But how we can do this programatically ?
Are you asking if you can do this for your app or lock the orientation for the device itself? Seems to me you're asking for the latter and I would have to ask why you want to do that. It's not possible to lock the orientation for the device, because that way it would be locked in portrait mode for other apps as well.
You can however only support the orientations you want yourself. A lot of apps only support portrait mode and games generally support landscape only.
You can set the supported device orientations of your app in XCode. At the viewcontroller.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Assuming you want to support both landscape orientations.
You can't do it programmatically -- it would be plain wrong for an app to change a setting that affects everything else.
In your own app, you can restrict the supported orientations by setting UISupportedInterfaceOrientations in your info.plist (see doc here). You can also restrict orientation per view through shouldAutorotateToInterfaceOrientation (see doc here)

App getting hanged while changing orientation

i know this is going to be a vague question, but please give a thought to this...
I am developing a book reader on ipad and it has many functionalities like highlight, notes etc. and all these functions are woking well. But the problem comes only when i try to rotate my device after implementing any function.. The app is geting struck(or hanged) after changing itz orientation....
Can anyone tell me why a app usually gets hanged???? Give a thought to this please. Your inputs will help me go a long way.....
Thanks
The problem might be with your control frame settings.
If your application support portrait mode alone means code as follows,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
else
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
and change the control frame accordingly.