Webview会自动调整为iphone中的纵向和横向视图 [英] Webview resizes automatically to portrait and landscape view in iphone
问题描述
我是iphone开发的新手。在我的应用程序中,我想在设备中显示带有c纵向Orientation的Web视图。它还应该支持横向。我使用了下面的方法,但没有预期的输出。
I am new to iphone development.In my app, i want to display the web view in device with c portrait Orientation.It should also support landscape orientation. I used the below method but there is no expected output.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==
UIInterfaceOrientationLandscapeRight);
}
请指导我。请帮帮我。谢谢
please guide me.Please help me out.Thanks
推荐答案
我认为你已经为webview设置了固定的框架。这对实现方向chage没有帮助
I think you have set the fixed frame for webview.That will not help while implementing orientation chage
试试这个:
使用此代码显示网页视图。使用您的网址更改堆栈溢出网址;
Use this code for displaying the web-view.Change the stack-overflow URL with your 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;
}
用于定位的网页视图更改
For web-view change with orientation
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
[webView stringByEvaluatingJavaScriptFromString:@"rotate(0)"];
}
else{
[webView stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
}
}
希望以上内容符合您的要求。
一切顺利。
Hope the above will satisfy your requirement. All the best.
这篇关于Webview会自动调整为iphone中的纵向和横向视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!