![](/img/trans.png)
[英]How to prevent “bounce” effect when a custom view redraws after zooming?
[英]UIWebView redraws on view did appear, how can I prevent this?
我正在使用UIWebView
應用程序,現在出現下面列出的問題,請幫助我進行解決。
ViewController
並返回時,它變白了一秒鍾,然后再次繪制了我的HTML內容。 有什么辦法可以防止這種情況? 我的html內容沒有更改,因此我可以將其設置為固定內容還是可以更快地繪制內容?
這是我在webview中設置html的方式:
webView.loadHTMLString(htmlData, baseURL: nil)
您的HTMl代碼沒有更改,因此將您的webView
加載代碼放在viewDidLoad
而不是viewDidAppear
,因為viewDidAppear
總是在顯示view
時調用,其中viewDidLoad
在加載view
時一次調用。
您可以在應用程序的生命周期中執行一次引導WebView的代碼,或進行相應的自定義。
// if you are navigating your application using navigation controller enables you to come back to the rootview without executing whole code of that class associated with view.
// this doesn't apply the whole life cycle of view controller
[self.navigationController pushViewController:vc animated:YES];
// if you navigating through below code this apply the whole life cycle concept of view controller.
[self presentViewController:vc animated:NO completion:nil];
您必須了解一下View Controller的生命周期,這是一個有用的Apple文檔
viewController生命周期簡短說明
ViewDidLoad-創建類並從xib加載時調用。 非常適合初始設置和一次性工作。
ViewWillAppear-在視圖出現之前立即調用,非常適合於隱藏/顯示字段或您希望在視圖可見之前每次進行的任何操作。 因為您可能會在視圖之間來回移動,所以每次視圖將出現在屏幕上時都會調用此方法。
ViewDidAppear-在視圖出現后調用-是啟動動畫或從API加載外部數據的好地方。
ViewWillDisappear / DidDisappear-與ViewWillAppear / ViewDidAppear相同的想法。
ViewDidUnload / ViewDidDispose-在目標C中,您可以在此處進行清理和發布內容,但是此操作是自動處理的,因此您在這里實際上不需要做很多事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.