I am creating an app on a splitview with tab bar controller. my problem is when i am on portrait and hide the masterview, my formsheet dismisses. Is there a way to prevent the rotation if there is a current formsheet shown?
Include this method in your code, you may want to add an additional if when your form sheet is dismissed. This bit of code will lock your view to landscape.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
} else {
return NO;
}
}
Related
I have following ViewControllers:
InformationViewController and cardViewController.
How can i make sure that informationViewController is in portrait mode and cant be rotated.
Then cardViewController should be in landscape mode and cant be rotated.
How can i implement this in each viewController. i've at the moment activated protrait, landscape right and left in General
In Information view controller
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
And in card view controller
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
Note: Please be sure in project general setting tick the both portrait and landscape modes in device orientation (Deployment Info)
In informationViewController:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
In cardViewController:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
Have a look at my answer to this question:
Force controllers to Change their orientation in Either Portrait or Landscape
(But don't use the deprecated methods. There are newer methods available which work either.)
It is easy to limit the view controllers to certain orientations. But see the other answer for how to force the device to actually rotate.
Without that trick: If a portrait only view controller becomes visible while the device is in landscape, then it will be displayed in landscape regardless how you limit its supported orientations.
i have a detailview where content is displayed. with a button i am presenting another view modally:
[self.viewController presentModalViewController:helpViewController animated:NO];
So, when i dismiss this helpViewController, the detailview is always in portraitMode.
Cant get it to the correct device orientation.
I have tried it with this to rotate it to device orientation:
if ([UIViewController respondsToSelector:#selector(
attemptRotationToDeviceOrientation)]) {
[UIViewController attemptRotationToDeviceOrientation];
}
It seems that after dismissing the helpViewController viewDidAppear is not called in detailView.
So how can i get that to work?
Plz try to set the detailview.m as
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
// Return YES for supported orientations
return YES;
// return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I have an app with several different tabs. The first of these tabs should only allow portrait rotations, however I want the rest of the tabs to be able to rotate freely. Is this even possible? If so how can I achieve this effect?
In the view controllers' .m file for the respective tabs you can set interface orientation as per your requirement to portrait or landscape.
Here is the the snippet of code block in the view controllers' .m file
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
I need a view that can display both in Portrait and landscape.But when I load another view I only want it show in landscape.
I have a view controller A.which can be shown in portrait and landscape.This view controller is create by the App delegate.
When I click a button on the view A.I create a view controller B which I want to display only in landscape.and load the view like [A.view addSubView:B.view].
When I rotate the device the function shouldAutorotateToInterfaceOrientation is called only in
controller A. No matter how I set the function in controller B.It can't be called.
On your first view, make sure that
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
return Yes;
}
And in your second view set it to
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Update:
Ok, try this...
In your main view controller/app delegate, where the shouldAutorotateToInterfaceOrientation is run every time the device rotates, put a global level variable. something like
.h
#interface NavAppDelegate : NSObject <UIApplicationDelegate> {
Bool *isMain;
}
.m
-(void)viewDidLoad {
isMain = Yes;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
if (isMain) {
return Yes;
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
// This bit is where you'll have to adapt it to how you change your views
// but it's a basic idea.
-(void)bitThatDoesTheViewChange:(viewController *) controller {
isMain = No;
*viewController = controller;
[viewController release];
isMain = Yes;
}
Is there a way to restrict view rotation to only one view controller?
For example the rest of the app stays in portrait mode but one view can be in either landscape or portrait mode.
Use this delegate method to control the rotation,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Return YES for supported orientations
return YES;
}
else
{
return NO;
}
}
return YES for the orientations you want to support and NO for others. You can implement this in all the view controllers.
You can implement the shouldAutorotateToInterfaceOrientation: method of each UIViewController. Returning YES for the orientations you want a given view controller to support will yield the desired result.
See the UIViewController docs.