我正在使用 Xamarin iOS 开发一个 iOS 应用程序,我有一个加载本地 html 的 webView,但是 webView 占据了整个屏幕,因此没有地方放置后退按钮。
这是我加载的 localhtml 代码:
using CoreGraphics;
using Foundation;
using System;
using System.CodeDom.Compiler;
using System.IO;
using UIKit;
namespace AppName
{
partial class View : UIViewController{
public View(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
var webView = new UIWebView(new CGRect(0, 20, View.Frame.Width, View.Frame.Height -20));
View.AddSubview(webView);
// Method 2 using LoadRequest
string fileName = "Content/local.html"; // remember case-sensitive
string localHtmlUrl = Path.Combine(NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localHtmlUrl, false)));
webView.ScalesPageToFit = false;
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
我做错了什么?
最佳答案
var webView = new UIWebView(new CGRect(0, 20, View.Frame.Width, View.Frame.Height -20));
您正在将 WebView 的框架设置为 Controller 框架的完整框架(y 位置除外,您将其设置为距离顶部 20 像素)。
我认为你应该阅读 UIView frame, bounds and center .
关于ios - 如何使用 Xamarin iOS 动态更改 webView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31750071/