I am trying to add a subview on a landscape only app in a landscape only mode. This seems to work fine on newer iPads, However when testing this on an iPad 2 the subview only seems to appear in a portrait mode. What could I be doing wrong here?
Edit: This UIView shows fine on IOS 8 and above but Does not show up properly for IOS 7.1
The Place where I add the subview:
MobileWebViewController *mobileViewController = [[MobileWebViewController alloc]
initWithNibName:@"MobileWebViewFrame"
bundle:[NSBundle mainBundle]];
[mobileViewController setUrlAddress:@"http://www.stackoverflow.com"]; //user defined function
[[UIApplication sharedApplication].keyWindow addSubview: mobileViewController.view];
Now in my MobileWebViewController I have this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle
*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[UIApplication sharedApplication] statusBarOrientation];
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate
{
return YES;
}
//For Older versions
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didRotateFromInterfaceOrientation:
(UIInterfaceOrientation)fromInterfaceOrientation
{
[UIViewController attemptRotationToDeviceOrientation];
}
- (void) setUrlAddress:(NSString *)url
{
self.urlAddress = url;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth;
[self setNeedsStatusBarAppearanceUpdate];
[[NSUserDefaults standardUserDefaults] synchronize];
self.MobileWebView.delegate = self;
self.MobileWebView.scalesPageToFit = NO;
self.MobileWebView.multipleTouchEnabled = NO;
self.MobileWebView.frame = CGRectMake(0,
self.MobileWebView.frame.origin.y,self.view.frame.size.width,
self.view.frame.size.height - self.MobileWebView.frame.origin.y);
self.MobileWebView.transform = CGAffineTransformIdentity;
}
where MobileWebView is:
@property (strong, nonatomic) IBOutlet UIWebView *MobileWebView;
from the xib file.
From what I could debug and see . The screen orientation seems to be still landscape but this particular view came in portrait possibly because of a different co ordinate system.