I used to allow rotate my ios app in ipad:
My issue is the white space in the right in landscape orientation, but in portrait is well.
I think that I put a condition if the orientation in landscape or in portrait and adjust the width of the view controller, but how can I adjust it? and what shall the condition be?
Please help!
Here are macros UIDeviceOrientationIsLandscape and UIDeviceOrientationIsPortrait
so rather checking separately you can do it like this ...
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
// code for landscape orientation
}
OR
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
// code for Portrait orientation
}
After check the orientation. you can apply condition.
and also please read autosizing
Related
I'm adding a view to view controller in which there are certain components. My project needs to support both orientation.
I designed the view controller using story board in landscape mode. When a button is pressed in the view controller the view is shown using the scaling animation.
It works perfect when its in landscape mode. When its in landscape mode and button is pressed it works perfect and also the rotation also works perfect. But if its in landscape mode and button is pressed the view doesn't get scaled according to the portrait mode and rotation is also a big problem.
I'm using autosizing and not auto layout
Can anyone please help me? Sorry for my bad english.
Any help is appreciated.
Autosizing has never proved to be the best solution for frame changes in orientation modes. Instead, change the frames manually in orientation delegate methods:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
check for your current orientation like:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
// change frames here for portrait mode
}
else
{
// change frames here for landscape mode
}
}
The iPhone has a orientation lock for portrait only. So I added a landscape orientation lock button to my UI that sets a landscape_orientation_locked variable to YES or NO. Then in shouldAutorotateToInterfaceOrientation: I basically do the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (landscape_orientation_locked)
return (UIInterfaceOrientationIsLandscape(interfaceOrientation));
return YES;
}
This works fine, except for one case. When I turn the iPhone to landscape orientation, toggle the orientation lock button, rotate the iPhone to portrait orientation and hit the button again. The interface orientation won't change from landscape to portrait. The iPhone has to be turned into landscape and then portrait orientation to trigger the interface rotation.
So my question is: Can I somehow 'force' the iPhone to re-evaluate it's current orientation?
Presenting and then dismissing a mock modal view controller should force an orientation check.
EDIT: Found the question where I first read about that:
Is there a documented way to set the iPhone orientation?
I developed app(navigation + tabbar) in portrait mode.
But now I want that if user change its orientation to landscape or
portrait then all should be rotate in that orientation.
You need to set each view's control autoresizingmask. You can do it through xib as well as code as per your need and add below method in all viewControllers and it should work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
Hope this help.
And have a look into your ".plist", you can define "Supported interface orientations" (UISupportedInterfaceOrientations) here.
I would like to do this because the keyboard buttons are slightly bigger in landscape mode than portrait and I will have older users using my app.
Does anybody know a way to do it??
Thanks.
The keyboard will show up in the orientation of the statusbar, which doesn't always change with rotations for some reason. So if you want to display that view only in landscape set [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft; or whichever orientation you want to prefer in your viewWillAppear method.
I need to block rotation to landscape orientation because my app crashes when it attempts to rotate views to landscape.
How do I block rotation to landscape and where can I setup the block such that it applies to all my views?
Thanks
In your view controllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation==UIInterfaceOrientationPortrait ) {
return YES;
} else {
return NO;
}
}
This will prevent your views from trying to rotate to landscape or upsidedown-portrait. However, this should be default. If you haven't set up code to handle landscape orientation then the views shouldn't be trying to rotate anyway. Your crashing is most likely coming from somewhere else.