I want to make an iPhone app which shows a view when iPhone is in portrait mode, and ANOTHER when iPhone is in landscape mode. I know there is many post about that but I don't understant the answer.
In a first time, to understand, I make test with a Tabbed Application, because I have already two views. When I tap on the second screen, I would like my iphone in landscape mode. (and in the first one in portrait mode).
On Apple website, and stackoverflow, I saw the following code :
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if ((orientation == UIInterfaceOrientationPortrait) ||
(orientation == UIInterfaceOrientationLandscapeLeft))
return YES;
return NO;
}
Or a similar code.
In my mainstoryboard, I put the second view in landscape, with the interface.
But when I run my app, and I tap on second screen, iPhone stay in portrait mode..
I tried to do the same thing with a single view app, and created new file (landscapeViewController) with .xib file, but I can't have a godd result!
[[UIDevice currentDevice] setOrientation: UIDeviceOrientationLandscapeLeft];
doesn't work in iOS7 (read only) And it is the same for this code :if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) { UIWindow *window = [[UIApplication sharedApplication] keyWindow]; UIView *view = [window.subviews objectAtIndex:0]; [view removeFromSuperview]; [window addSubview:view]; }
(very curious code ...) – papay0