【发布时间】:2015-04-22 21:54:59
【问题描述】:
我正在尝试以仅横向模式在仅横向应用程序上添加子视图。这似乎在较新的 iPad 上运行良好,但是在 iPad 2 上进行测试时,子视图似乎只以纵向模式出现。我在这里做错了什么?
编辑:此 UIView 在 IOS 8 及更高版本上显示正常,但在 IOS 7.1 上显示不正确
我添加子视图的地方:
MobileWebViewController *mobileViewController = [[MobileWebViewController alloc]
initWithNibName:@"MobileWebViewFrame"
bundle:[NSBundle mainBundle]];
[mobileViewController setUrlAddress:@"http://www.stackoverflow.com"]; //user defined function
[[UIApplication sharedApplication].keyWindow addSubview: mobileViewController.view];
现在在我的 MobileWebViewController 我有这个:
- (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;
}
MobileWebView 在哪里:
@property (strong, nonatomic) IBOutlet UIWebView *MobileWebView;
来自 xib 文件。
从我可以调试和看到的 .屏幕方向似乎仍然是横向的,但这个特定的视图是纵向的,可能是因为坐标系不同。
【问题讨论】:
标签: ios objective-c ipad uiwebview screen-orientation