- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
每当我在我的应用程序中使用的 UIWebView 中重新加载网站时,网站就会向下移动。我不知道为什么会这样,因为当我在 Safari 中访问网站的移动版本时,网站不会向下滚动。
下面是 UIWebView 的代码:
import Foundation
import UIKit
import SVProgressHUD
import Canvas
class WebViewHome: UIViewController, UIWebViewDelegate, SWRevealViewControllerDelegate{
@IBOutlet weak var heightConstraint: NSLayoutConstraint!
@IBOutlet weak var WebViewContainer: UIView!
@IBOutlet weak var WebViewTst: UIWebView!
@IBOutlet weak var animView: CSAnimationView!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.topItem!.title = "Home"
let URL = NSURL(string: "https://gunnoracle.com/")
WebViewTst.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest)
let topSpace = -190
let bottomSpace = -3045
let leftSpace = -40
let rightSpace = -40
WebViewTst.scrollView.contentInset = UIEdgeInsets(top: CGFloat(topSpace), left: CGFloat(leftSpace), bottom: CGFloat(bottomSpace), right: CGFloat(rightSpace))
WebViewTst.scrollView.bounces = false
WebViewTst.scrollView.maximumZoomScale = 1.0
WebViewTst.scrollView.minimumZoomScale = 1.0
WebViewTst.delegate = self
}
override func viewDidAppear(_ animated: Bool) {
self.revealViewController().delegate = self
}
func revealController(_ revealController: SWRevealViewController!, didMoveTo position: FrontViewPosition) {
if(revealController.frontViewPosition == FrontViewPosition.right){
animView.isHidden = true
UIView.animate(withDuration: 0.5, animations: {
self.WebViewTst.layer.zPosition = 1
self.WebViewTst.transform = CGAffineTransform(translationX: 0, y: -65);
self.view.layoutIfNeeded()
})
}
}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
switch navigationType {
case .linkClicked:
let topSpace = -170
let bottomSpace = -2840
let leftSpace = -40
let rightSpace = -40
animView.startCanvasAnimation()
WebViewTst.scrollView.contentInset = UIEdgeInsets(top: CGFloat(topSpace), left: CGFloat(leftSpace), bottom: CGFloat(bottomSpace), right: CGFloat(rightSpace))
WebViewTst.scrollView.bounces = false
WebViewTst.scrollView.maximumZoomScale = 1.0
WebViewTst.scrollView.minimumZoomScale = 1.0
WebViewTst.delegate = self
default:
break
}
return true
}
func webViewDidStartLoad(_ webView: UIWebView) {
SVProgressHUD.show(withStatus: "Loading...")
SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)
SVProgressHUD.setRingThickness(1.0)
NSLog("Webview has started loading")
}
func webViewDidFinishLoad(_ webView: UIWebView) {
SVProgressHUD.dismiss()
NSLog("Webview has successfully loaded")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
最佳答案
这是对问题下评论的跟进。
请注意,此代码未经测试,因此只能用作指南。
为了抵消顶部的内容插入并保持滚动位置,您可以使用类似于
的代码- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat currentYOffset = scrollView.contentOffset.y;
CGFloat topIntest = scrollView.contentInset.top;
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, currentYOffset - topIntest);
}
如果没有看到您的确切项目和预期的视觉输出,就很难给出完美的答案。
理想情况下,您应该以稍微不同的方式处理此解决方案。您上面的代码使用固定的 contentInset
告诉我您需要您的页面具有特定的填充才能看起来正确。为确保将性能保持在最高水平,您真正应该做的是在您正在加载的网页中实现该填充。
如果您可以访问网页源代码,请在 body 标签上使用 CSS 填充样式来复制您想要的间距/填充/对齐方式。
如果您无权访问网页源代码,您也可以使用以下方式将网页加载到字符串
NSString *content = [NSString stringWithContentsOfURL:@"http://example.com "encoding:NSUTF8StringEncoding error:nil];
然后您可以将自己的样式注入(inject) HTML。
有很多方法可以做到这一点,一个例子是:
NSURL *contentURL = [NSURL URLWithString:@"http://example.com"];
//load content to string
NSString *content = [NSString stringWithContentsOfURL:contentURL encoding:NSUTF8StringEncoding error:nil];
//create css style to inject
NSString *paddingCSS = @"<style> body { margin-top: -190px; margin-left:-40px; margin-right:-40px; margin-bottom:-3045px } </style></head>";
//inject the string just before the </head> tag
[content stringByReplacingOccurrencesOfString:@"</head>" withString:paddingCSS options:NSCaseInsensitiveSearch range:NSRangeFromString(content)];
//load the webview using the content string.
//Set the baseURL to ensure relative links etc. still work
[self.webView loadHTMLString:content baseURL:contentURL];
关于ios - 刷新时的 UIWebView 网站向下移动 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42285823/
我有这个网站,这个特定页面是安全的,但是当它回发时,它回发到一个不安全的页面。如何解决? 我正在使用 ASP.NET 向导。我有这个页面 - checkout.aspx,页面包含这个控件 checko
我有 2 个 azure 网站 - 两个独立的项目 我现在有 2 个网址: myazurewebsite.azurewebsites.net myazureblog.azurewebsites.net
我有 2 个 azure 网站 - 两个独立的项目 我现在有 2 个网址: myazurewebsite.azurewebsites.net myazureblog.azurewebsites.net
环境: 旧网站: React 托管在 Heroku URL( http://sameurl.com ) 新网站: Java 托管在 Heroku URL ( http://sameurl.com )
我已在 Windows Azure 上注册了一个测试帐户来对其进行测试。我构建了一个 Hello world ASP.NET Web 应用程序 + 数据库只是为了测试。 我安装了 Visual Stu
我有一个可以收集和显示各种测量值的产品(不会详细介绍)。正如人们所期望的那样,显示部分是一个数据库+建立在其之上的网站(使用 Symfony)。 但是,我们可能还会创建一个 API 来向第三方公开数据
这个问题在这里已经有了答案: Software keyboard resizes background image on Android (16 个答案) 关闭 8 年前。 我有一个类似的问题:So
这个问题似乎很常见,但我真的无法根据现有答案解决问题。 我有一个简单的 maven 项目,没有任何复杂的部署配置等,并且想在点击“mvn site”时生成一个 Maven CheckStyle 报告。
有没有人看过有关何时进行横向扩展与纵向扩展的最佳选择的任何分析或信息。什么时候一个比另一个更有意义。 目前,在标准模式和基本模式下,2 个小型实例的费用与 1 个中型实例的费用相同。 拥有 2 个小型
有没有办法找到 azure 网站何时停止? (我通过门户网站停止了网站,但我不记得是什么时候......) 我正在寻找一些日志,但没有找到任何有用的内容。 谢谢。 最佳答案 您拥有的最接近的是 azu
我目前在 Azure VM 的 IIS 中拥有一个网站。我已将该站点复制到 2 个可用区域中的 2 个虚拟机上。 这可以保护网站免遭停机。 我需要为高负载时刻实现一些可扩展性。这似乎就是创建音阶集的目
我有一个托管在 Azure 上的网站 ( http://mike-ward.azurewebsites.net/ )。我从 Azure 门户设置了一个指向(引用?)我的网站的 Azure CDN。根据
我有一个 Azure 网站(不是 Web 角色),有 2 个槽:生产和暂存。 我只想为生产插槽启用 CDN,而不是为登台启用,问题是我找不到识别主机插槽的方法。 RoleEnvironment 不可用
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等建议的问题。您可以编辑问题,以便可以用事实和引用来回答它。 4年前关
我们正在考虑将一些网站从 Azure 云服务迁移到 Azure 网站(事情似乎就是这样进行的)。显然,我们被明确告知云服务不会保留文件系统状态,因为它们会在机器故障时重新部署。 我假设网站是基于 Bl
我有一个 Azure 网站,需要使用在 VM 上运行的 Elasticsearch 服务。 虽然我需要能够锁定对 Elasticsearch 的访问,以便只有 Azure 网站可以访问它,但我似乎无法
我有一个 azure 网站,位于 yis3.azurewebsites.net - 我已将其提升为“共享”网站,以便我可以使用自定义域。我拥有从 123-reg.co.uk 购买的域名 yorkshi
我正在使用 abcPDF 动态创建 PDF。 我想保存这些 PDF,以便客户随时检索。最简单的方法(也是我现在在当前服务器上所做的方法)是将完成的 PDF 保存到文件系统。 看来我一直坚持使用 blo
我们正在尝试了解 Windows Azure 管理 API 为 Azure 网站(而非 Webroles)返回的监控数据的复杂性 例如,下图描述了为 CPUTime 检索的数据点。它似乎表明,在晚上
看起来真的很愚蠢,因为我找不到它: 门户网站似乎不太直观,我如何为一个“网站”付费并在其中运行最多 500 个网站?我想当我通过单击左下角的加号添加“网站”时,我添加了整个虚拟机而不是子站点。如何仅添
我是一名优秀的程序员,十分优秀!