Webview resizes automatically to portrait and landscape view in iphone(Webview 自动调整大小为 iphone 中的纵向和横向视图)
问题描述
我是 iphone 开发新手.在我的应用程序中,我想在具有 c 纵向方向的设备中显示 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 设置了固定框架,这对实现方向改变没有帮助
I think you have set the fixed frame for webview.That will not help while implementing orientation chage
试试这个:
使用此代码显示网络视图.使用您的 URL 更改堆栈溢出 URL;
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;
}
网页视图随方向变化
- (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 中的纵向和横向视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Webview 自动调整大小为 iphone 中的纵向和横向视图
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01