I'm wondering why iPad project based on UITabBarController won't autorotate when i specify some of the tab should autorotate in landscape mode and the other will autorotate in landscape and portrait mode.
i've used the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
for all the UIViewController and specify if landscape return YES; other wise return NO;
In the other hand, if the UIViewController should rotate in landscape and portrait i've justreturn YES;` always.
Thx in advance.
for all the UIViewController you are loading in tabbarcontroller you must return True in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Note:
A tab bar controller will not auto rotate unless ALL the controllers it contains also auto rotate.
from Rotate one UIViewController in UITabBar application -->>
There is no easy way to have only one view in landscape mode, while the others are in landscape, nor an easy way to programmatically switch to landscape mode.
One possible approach would be using a CGAffineTransform to transform your view in your viewWillAppear (i.e., right before the view is shown):
- (void)viewWillAppear:(BOOL)animated; {
//-- Adjust the status bar
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
//-- Rotate the view
CGAffineTransform toLandscape = CGAffineTransformMakeRotation(degreesToRadian(90));
toLandscape = CGAffineTransformTranslate(toLandscape, +90.0, +90.0 );
[self.view setTransform:toLandscape];
}
Related
I want to show one view controller in both orientation in iPhone. And when the screen is opening the preferred orientation should be portrait only. Then according to the device orientation it'll rotate. I found some solution and the screen is rotating too. But when I'm entering the screen it is auto rotating to landscape and than I've to manually rotate it to portrait.
Is there a simple solution to this problem?
You should implement preferredInterfaceOrientationForPresentation and
supportedInterfaceOrientations like:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIDeviceOrientationPortrait;
}
//You don't actually need to implement this as UIInterfaceOrientationMaskAllButUpsideDown is the default for iPhone
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
My keyboard appears in portrait mode when i rotate a single view to landscape.
-(void)viewWillAppear:(BOOL)animated
{
CGAffineTransform newTransform = CGAffineTransformMake(0.0,1.0,-1.0,0.0,0.0,0.0);
self.view.transform = newTransform;
}
If you want a single view controller to support only landscape orientation you should do it the 'Apple way" by implementing
-(NSUInteger)supportedInterfaceOrientations
Remeber to set "View controller-based status bar appearance" to YES in your plist file
See this link for more details - Supporting Multiple Interface Orientations
I created a "Single View Application" project and set all options to launch and support only landscape orientation. But the app launches with its window in portrait orientation.
Console output says that the window after application:didFinishLaunchingWithOptions: is:
{{0, 0}, {768, 1024}}
I added a standard system button to view of ViewController to illustrate that the app is landscape and not portrait, but that the window is portrait.
Because stack overflow has white background I colored the right part gray in Photoshop so you can see it:
In application:didFinishLaunchingWithOptions: I colored the window red. It is clearly not in landscape orientation.
I have tried all the tricks I know:
1) Info.plist contains UISupportedInterfaceOrientations key with:
UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight
2) Info.plist contains UISupportedInterfaceOrientations~ipad key with:
UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight
3) Info.plist contains UIInterfaceOrientation key for initial interface orientation:
UIInterfaceOrientationLandscapeRight
4) Clicked on the project in Xcode and then unchecked all portrait options and only checked the landscape options:
5) AppDelegate and the ViewController both have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
6) AppDelegate has:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Xcode created two storyboard files. I am only testing on iPad right now. One is Main_iPad.storyboard and it shows a view controller which was in portrait. But it was only a simulated interface metric. Changed to landscape and as expected no effect.
During app launch I check UIScreen bounds and it also is clearly portrait, not landscape:
CGRect screenBounds = [[UIScreen mainScreen] bounds]; // {{0, 0}, {768, 1024}}
How can I make it launch in landscape and create a window in landscape orientation?
I had a similar problem before, so maybe they're related...
I had a problem because I was creating my view programmatically in my view controller's initWithNibName:bundle: and for whatever reason, doing so orients the new view in portrait mode while the rest of the app is running landscape.
I found two fixes for this problem. 1) Create the view using your storyboard instead of programmatically or 2) move the code to create the view from your view controller's initWithNibName:bundle: method and place it in the view controller's -viewDidLoad: method like this:
-(void)viewDidLoad {
//Create your view programmatically
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
//Customize view
[self.view addSubview:view];
}
That was the solution for a similar problem I had. While I recognize that there's a myriad of ways that we programmers can make things not work the right way, I hope this is the answer!
While in interface builder click on View Controller, then in Size Inspector switch Simulated Size to Freeform (from Fixed), enter 1024 for Width and 768 for Height. It works for me.
I ma trying to lock screen orientation to only landscape orientation when a certain image is still visible, then when the image is hidden, unlock all orientations (targeting iOS 6):
-(BOOL)shouldAutorotate{
if (self.splashImageView.hidden == NO) {
return UIInterfaceOrientationMaskPortrait;//gets called when image is visible
}else{
return UIInterfaceOrientationMaskAll;//gets called when image is hidden
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self shouldAutorotate];
}
As you may notice, shouldAutorotate is called properly but the screen is always supporting landscape orientation even when the image is still visible, is there something missing?
P.S: Please note I am trying to get that to work on a tabbar view controller (a UIViewController subclass).
In your appdelegate you have those two methods.but do you have setting like in your project settings -> go to summary tab and see if orientation is set to only landscape or all.Just try to set those.
In my App, I have a tabbarController and 5 view controllers managed by it.
I only want one UIView rotate to landscape and make the tabbar invisible when rotate to landscape. In current condition, all my views autorotate themselves which is not what I expect.
The code of UIView which I dont want it rotate is:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationLandscapeLeft) {
// stop the rotation, keep it as portrait orientation
// from app document, it says for UITabbarController, rootview which is uitabbarcontroller and views managed by it should all agree on the same orientation otherwise they wont rotate.
// how can i do this?
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}