久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UIScrollView 內的 iOS UIWebView

iOS UIWebView inside a UIScrollView(UIScrollView 內的 iOS UIWebView)
本文介紹了UIScrollView 內的 iOS UIWebView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想在 UIScrollView 中有一個 UIWebView.UIWebView 有時會超出 iPhone 屏幕的范圍,因此我需要一種滾動視圖的方法,以便可以看到所有內容(但我不想使用 UIWebView 的內置滾動).所以我正在考慮將所有內容放在 UIScrollView 中,然后使 UIScrollView 的高度等于 UIWebView 和其中其他視圖的高度.

I want to have a UIWebView inside a UIScrollView. The UIWebView will sometimes go out of bounds of the iPhone screen so I need a way to scroll the view so I can see all the content (but I don't want to use the built in scrolling of the UIWebView). So I'm thinking of putting all the content inside of a UIScrollView and then making the height of the UIScrollView to equal the height of the UIWebView and other views that are in it.

這是幫助描述我的問題的圖片:

Here's an image to help describing my problem:

推薦答案

我做了完全一樣的事情.以下是我的工作方式:

I did exactly the same thing. Here's how I made it work:

  1. 將 UIWebView 添加為 UIScrollView 的子視圖(顯然 ;-)
  2. 禁用 UIWebView 的本機滾動(您可以通過遍歷 UIWebView 的子視圖來做到這一點,直到找到它是 UIScrollView 并在其上設置 scrollEnabled = NO.
  3. 將 UIScrollView 的 contentSize 和 UIWebView 的框架設置為 UIWebViews HTML 內容的大小.

最后一點有點棘手,因為當 webViewDidFinishLoad: 在 UIWebViewDelegate 上被調用時,您無法確定 HTML 是否完全呈現.

The last point is bit tricky because you cannot be sure that the HTML is completely rendered when webViewDidFinishLoad: gets called on the UIWebViewDelegate.

這是獲取 HTML 內容大小的可靠方法:

Here's a reliable way to get the HTML content size:

1.在 HTML 文檔準備好時調用的 HTML 中添加一個 javascript 函數:

1.Add a javascript function to the HTML that gets called when the HTML Document is ready:

window.onload = function() {
    window.location.href = "ready://" + document.body.offsetHeight;
}

這個函數發送一個在其 URL 中具有內容高度的請求.

This functions sends a request that has the content height in it's URL.

2.在你的 UIWebViewDelegate 你攔截這個請求:

2.In your UIWebViewDelegate you intercept this request:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
        NSURL *url = [request URL];
        if (navigationType == UIWebViewNavigationTypeOther) {
           if ([[url scheme] isEqualToString:@"ready"]) {
               float contentHeight = [[url host] floatValue];
               yourScrollView.contentSize = CGSizeMake(yourScrollView.frame.size.width, contentHeight + yourWebView.frame.origin.y);
               CGRect fr = yourWebView.frame;
               fr.size = CGSizeMake(yourWebView.frame.size.width, contentHeight);
               yourWebView.frame = fr;

               return NO;       
        }

        return YES;
}

希望有幫助

更新

這里是 Swift 2 版本:

Here is the Swift 2 version:

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    guard navigationType == .Other else { return true }
    if let url = request.URL, let host = url.host {
        guard url.scheme == "ready" else { return true }
        if let contentHeight = Float(host) {
            yourScrollView.contentSize = CGSizeMake(yourScrollView.bounds.size.width, CGFloat(contentHeight))
            var fr = webView.frame
            fr.size = CGSizeMake(fr.size.width, CGFloat(contentHeight))
            webView.frame = fr
        }

        return false
    }

    return true
}

這篇關于UIScrollView 內的 iOS UIWebView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
iOS/Swift - Hide/Show UITabBarController when scrolling down/up(iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarController)
Xcode amp; Swift - Detecting user touch of UIView inside of UIScrollView(Xcode amp;Swift - 在 UIScrollView 內檢測 UIView 的用戶觸摸)
主站蜘蛛池模板: 亚洲免费人成在线视频观看 | 视频一区在线 | 中文字幕一区二区三区精彩视频 | 国产99久久| 日韩精品区| 国产精品二区三区 | 狠狠爱网址 | 久久精品免费 | 久久久精| 久久久久国产精品 | 一区二区三区国产精品 | 欧美精品99| 久久久91精品国产一区二区三区 | 中文字幕免费视频 | 台湾佬成人网 | 男女视频在线观看免费 | 日韩免费网站 | 人人干人人玩 | 一区二区三区四区视频 | 亚洲精品乱 | 免费观看黄色一级片 | 色婷婷一区二区三区四区 | 免费在线一区二区 | 久久久国产一区 | 日日夜夜天天久久 | 日本高清视频在线播放 | 嫩呦国产一区二区三区av | 欧美午夜精品 | 91精品国产91久久久久游泳池 | 91中文字幕在线观看 | 中文字幕蜜臀 | 色射综合| 成人日韩| 草草视频在线观看 | 狠狠躁夜夜躁人人爽天天高潮 | av男人的天堂在线 | 国产高清视频在线播放 | 欧美成人一区二区 | 91操操操 | 男女污网站 | 精精国产视频 |