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

UIScrollView 內(nèi)的 iOS UIWebView

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

問題描述

我想在 UIScrollView 中有一個(gè) UIWebView.UIWebView 有時(shí)會(huì)超出 iPhone 屏幕的范圍,因此我需要一種滾動(dòng)視圖的方法,以便可以看到所有內(nèi)容(但我不想使用 UIWebView 的內(nèi)置滾動(dòng)).所以我正在考慮將所有內(nèi)容放在 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 的本機(jī)滾動(dòng)(您可以通過遍歷 UIWebView 的子視圖來做到這一點(diǎn),直到找到它是 UIScrollView 并在其上設(shè)置 scrollEnabled = NO.
  3. 將 UIScrollView 的 contentSize 和 UIWebView 的框架設(shè)置為 UIWebViews HTML 內(nèi)容的大小.

最后一點(diǎn)有點(diǎn)棘手,因?yàn)楫?dāng) webViewDidFinishLoad: 在 UIWebViewDelegate 上被調(diào)用時(shí),您無法確定 HTML 是否完全呈現(xiàn).

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 內(nèi)容大小的可靠方法:

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

1.在 HTML 文檔準(zhǔn)備好時(shí)調(diào)用的 HTML 中添加一個(gè) javascript 函數(shù):

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;
}

這個(gè)函數(shù)發(fā)送一個(gè)在其 URL 中具有內(nèi)容高度的請(qǐng)求.

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

2.在你的 UIWebViewDelegate 你攔截這個(gè)請(qǐng)求:

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
}

這篇關(guān)于UIScrollView 內(nèi)的 iOS UIWebView的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動(dòng)布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點(diǎn)擊手勢(shì)獲取索引或標(biāo)簽值)
UIScrollView not scrolling regardless of large contentSize(無論內(nèi)容大小如何,UIScrollView 都不會(huì)滾動(dòng))
UIScrollView zooming with Auto Layout(UIScrollView 使用自動(dòng)布局縮放)
iOS/Swift - Hide/Show UITabBarController when scrolling down/up(iOS/Swift - 向下/向上滾動(dòng)時(shí)隱藏/顯示 UITabBarController)
Xcode amp; Swift - Detecting user touch of UIView inside of UIScrollView(Xcode amp;Swift - 在 UIScrollView 內(nèi)檢測(cè) UIView 的用戶觸摸)
主站蜘蛛池模板: 久久久久成人精品 | 久久神马 | 久久国产精品偷 | 日本免费一区二区三区 | 精品亚洲一区二区三区 | 国产中文字幕网 | 日韩精品视频一区二区三区 | 红色av社区| 久久久久国产一区二区三区 | 亚洲国产网 | 午夜激情免费 | 亚洲视频二区 | 日韩精品一区二区在线 | 少妇特黄a一区二区三区88av | 日韩免费视频 | 国产精品揄拍一区二区久久国内亚洲精 | 亚洲视频免费在线观看 | 日韩成人精品一区 | 久久精品亚洲 | www操操| 91精品国产色综合久久 | 国产一在线观看 | 久久影音先锋 | 欧美极品一区二区 | 午夜影视在线观看 | 成人av电影在线观看 | av香蕉| 神马久久久久久久久久 | 精品三级| 精品国产乱码久久久久久a丨 | 日韩毛片在线观看 | 亚洲国产自产 | 每日在线更新av | 国产精品1区 | 91久久久精品国产一区二区蜜臀 | 久热中文字幕 | 久草成人| 中文字幕一区二区三区精彩视频 | 一区二区三区精品视频 | 亚洲日本欧美日韩高观看 | 欧美一级片在线 |