Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iphone中,Webview会自动调整为纵向和横向视图_Iphone_Uiwebview_Landscape_Screen Orientation - Fatal编程技术网

在iphone中,Webview会自动调整为纵向和横向视图

在iphone中,Webview会自动调整为纵向和横向视图,iphone,uiwebview,landscape,screen-orientation,Iphone,Uiwebview,Landscape,Screen Orientation,我是iphone开发新手。在我的应用程序中,我想在设备中以c纵向显示web视图。它还应该支持横向。我使用了下面的方法,但没有预期的输出 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientat

我是iphone开发新手。在我的应用程序中,我想在设备中以c纵向显示web视图。它还应该支持横向。我使用了下面的方法,但没有预期的输出

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{

return (interfaceOrientation == UIInterfaceOrientationPortrait || 

 interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == 

UIInterfaceOrientationLandscapeRight);
}

请引导我。请帮助我。谢谢

如果您想支持任何方向,请返回

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{
    return YES;
}

我认为您已经为webview设置了固定框架。这对实现方向更改没有帮助

试试这个:

使用此代码显示web视图。使用URL更改堆栈溢出URL

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;

webView = [[UIWebView alloc] initWithFrame:webFrame];

[contentView addSubview:webView]; 
webView.scalesPageToFit = YES;
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[webView setBackgroundColor:[UIColor clearColor]];
NSString *urlAddress = @"https://www.stackoverflow.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
webView.delegate =self;
[webView release];
支持定向

   - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{
return YES;

}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
 [webView stringByEvaluatingJavaScriptFromString:@"rotate(0)"];

}
else{
    [webView stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
}
}
用于随方向更改web视图

   - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{
return YES;

}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
 [webView stringByEvaluatingJavaScriptFromString:@"rotate(0)"];

}
else{
    [webView stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
}
}
希望以上内容能满足您的要求。
祝您一切顺利。

谢谢。是否要在我的webview中显示工具栏?我怎样才能做到这一点?。我无法在我的webview中看到工具栏。@请将选项卡栏作为子视图插入。。。[self.view insertSubview:tBar belowSubview:contentView];将tBar更改为您使用过的工具栏。这在iOS 6中已被弃用: