Reputation: 2092
I realize there a many questions relating to this issue, however i have not found one that solves my issue.
To start, I have set this code in my menu.h
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES; }
The status bar changes with orientation but the views are not rotating or resizing. In order to try to narrow down my issue, I decided to try to switch two views within one .xib based on orientation
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
-(void) orientationChanged:(NSNotification *)object
{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
In the iOS simulator, the view definitely changes to the specific views. However the landscape view shows up as if it was portrait and sideways.
my landscape view in IB
My landscape view in the iOS simulator after changing orientation
What am I doing wrong here? I can't figure it out, any help would be greatly appreciated. Thank you in advance. ** EDIT: New Code Below ** Okay.. my issue is that the view loads properly in landscape, it's just sideways. So the Landscape view loads, just sideways. My revised code based on @Seega is:
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
[[TTNavigator navigator] setCustomTarget:self];
[[TTNavigator navigator] setCustomAction:@selector(photoAction)];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIDeviceOrientationLandscapeLeft || toInterfaceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
-(void) orientationChanged:(NSNotification *)object
{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
Upvotes: 0
Views: 1633
Reputation: 2092
Hey thank you all for your help. I had a friend help and am not entirely sure was the problem. I can tell you the things I know he did do.
Disabled our ads temporarily
deleted the second view entirely and went with native orientation and resizing
added this to almost every .m file.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
As well a programmatically changed a few of the other views similar to this
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight)
{
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
self.Button.frame = CGRectMake(27,96,86,86);
self.Label.frame = CGRectMake(27,162,86,21);
}
else
{
self.Button.frame = CGRectMake(18,100,86,86);
self.Label.frame = CGRectMake(18,164,86,21);
}
}
}
Sorry, I can't fully explain the answer, I do not fully understand everything that was included in the project that affected the orientation. I am still very new to iOS development.
Upvotes: 0
Reputation: 4089
Idea!!!
If you are setting up the views in interface builder and then switching the actual view thats being displayed when the view rotates then you need to build that View in that particular orientation, not just size it to fit the orientation.
To check this:
If your view says 'Portrait' for the view you want to represent your landscapeView then it could be that xcode is rotating your landscape view to portrait and messing with your presentation.
Let me know if this helped.
Upvotes: 1
Reputation: 3390
You should better simply use
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
to handle the rotations instead of creating a own one.
And now you can delete all the notification stuff.
Upvotes: 1
Reputation: 4089
I would suggest putting your code in :
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
instead of making a new method. This will get called automatically if the shouldAutorotateToInterfaceOrientation method returns YES for that rotation.
Also there is a difference between UIDeviceOrientation and UIInterfaceOrientation so make sure your referencing the correct one. Your existing code would be changed to the following:
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
Also you can use a macro to check the interface orientation keeping your code cleaner.
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
Upvotes: 4
Reputation: 840
Can you make sure, you have all the orientation support selected as follows. I tried this, and it seems to be working fine for me.
Upvotes: 1