【发布时间】:2014-05-25 07:09:41
【问题描述】:
我有一个应用程序需要所有视图都处于纵向,而一个视图 (UIWebview) 需要支持纵向和横向。
为了设置默认的纵向,我把它放在我的应用代理中:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
//NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
if(flagOrientationAll == YES){
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskPortrait;
}}
并且我已经设法使用这种方法将我的 webview 安排为纵向/横向关于用户方向(也从 stackoverflow 获得)
-(void)viewWillAppear:(BOOL)animated
{
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
//NSLog(@"viewWillDisappear -- Start");
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = NO;
}
并使用两个 UIView 来呈现纵向和横向:
-(void)viewWillLayoutSubviews {
BOOL layoutIsPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
if (layoutIsPortrait) {
self.view = self.pView;
[self.pView addSubview:pwebView];
}else{
self.view = self.lView;
[self.lView addSubview:lwebView];
}}
然后使用以下代码关闭 webview:
- (IBAction)doneButtonTapped:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
但是,当它以横向状态关闭时,前一个屏幕(调用 web 视图的屏幕)以横向而不是默认(纵向)呈现。 在 webview 关闭后我怎样才能让它仍然以纵向显示?
谢谢
【问题讨论】:
标签: ios objective-c uiwebview