【发布时间】:2012-08-26 15:31:20
【问题描述】:
我是 iphone 开发新手。在我的应用程序中,我使用了许多 viewController、Web 视图、工具栏、标签栏等。在这里,我想在所有网络视图中实现方向(纵向或横向,反之亦然)相应的设备视图。我可以在所有 Web 视图中实现方向,除了那些 Web 视图位于标签栏控制器 Web 视图下(它可能是标签栏视图控制器或标签栏控制器视图的子视图之一)。
这里我使用下面的代码添加网页视图,
contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view = contentView;
self.view.autoresizesSubviews = YES;
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y -= 20.0;
webView1 = [[UIWebView alloc] initWithFrame:webFrame];
[contentView addSubview:webView1];
并使用以下方法来实现定位,
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation
{
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
[webView1 stringByEvaluatingJavaScriptFromString:@"rotate(0)"];
}
否则 {
[webView1 stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
}
}
请任何人提供解决方案!
【问题讨论】:
标签: iphone uiwebview orientation