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

檢測 UIWebView 的滾動視圖 contentSize 的變化

detect changes to UIWebView#39;s scroll view#39;s contentSize(檢測 UIWebView 的滾動視圖 contentSize 的變化)
本文介紹了檢測 UIWebView 的滾動視圖 contentSize 的變化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在 UIScrollView 內容的底部設置 UIView,因此我將視圖的位置設置為滾動視圖的 contentsize 高度.但是我的滾動視圖是 UIWebView 的子視圖,因此當加載圖像時,內容大小的高度會發生變化,而我應該位于滾動視圖底部的視圖最終會出現在中間......

I'm trying to set a UIView at the bottom of the content of a UIScrollView, do to so I set the view's position to the scrollview's contentsize height. But my scrollview is a subview of a UIWebView so when images are loaded, the contentsize height changes and my view which should be at the bottom of the scrollview ends up in the middle...

所以我正在尋找一種在滾動視圖的內容大小發生變化時得到通知的方法.我嘗試將其子類化并更改 contentsize 的設置器以發送 NSNotification:

So I am looking for a way to be notified when the scrollview's contentsize changes. I've tried to subclass it and change the setter for contentsize to send a NSNotification:

@implementation UIScrollView (Height)

-(void)setContentSize:(CGSize)contentSize
{
    _contentSize=contentSize;
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"scrollViewContentSizeChanged" object:nil]];
}

@end

但在編譯時我得到錯誤提示:

But on compile I get and error saying:

_OBJC_IVAR_$_UIScrollView._contentSize",引用自:-[UIScrollView(Heigth) setContentSize:] 在 MyClass.old: 未找到架構 armv7 的符號

"_OBJC_IVAR_$_UIScrollView._contentSize", referenced from: -[UIScrollView(Heigth) setContentSize:] in MyClass.o ld: symbol(s) not found for architecture armv7

知道 setter 應該如何子類化嗎?

Any idea how the setter should be subclassed ?

謝謝!

推薦答案

也許您可以使用鍵值觀察 (KVO) 來檢測內容大小的變化.我沒試過,但代碼應該是這樣的:

Perhaps you can use key-value observing (KVO) to detect changes to the content size. I haven't tried it, but the code should look like this:

static int kObservingContentSizeChangesContext;

- (void)startObservingContentSizeChangesInWebView:(UIWebView *)webView {
    [webView.scrollView addObserver:self forKeyPath:@"contentSize" options:0 context:&kObservingContentSizeChangesContext];
}

- (void)stopObservingContentSizeChangesInWebView:(UIWebView *)webView {
    [webView.scrollView removeObserver:self forKeyPath:@"contentSize" context:&kObservingContentSizeChangesContext];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (context == &kObservingContentSizeChangesContext) {
        UIScrollView *scrollView = object;
        NSLog(@"%@ contentSize changed to %@", scrollView, NSStringFromCGSize(scrollView.contentSize));
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

如果這不起作用,您可能需要調整 setContentSize: 方法.方法調配讓您的替換方法調用原始方法,這是您將新的內容大小傳遞給滾動視圖所需的操作.

If that doesn't work, you may need to swizzle the setContentSize: method. Method swizzling lets your replacement method call the original method, which is what you need to do to pass the new content size on to the scroll view.

您可以在此處閱讀有關方法調配的更多信息:http://www.mikeash.com/pyblog/friday-qa-2010-01-29-method-replacement-for-fun-and-profit.html

You can read more about method swizzling here: http://www.mikeash.com/pyblog/friday-qa-2010-01-29-method-replacement-for-fun-and-profit.html

我認為這是最流行的 swizzling 代碼:https://github.com/rentzsch/jrswizzle

I think this is the most popular code for swizzling: https://github.com/rentzsch/jrswizzle

這篇關于檢測 UIWebView 的滾動視圖 contentSize 的變化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的邊緣工作) - IT屋-程序員軟件開發技術分享社
ImageView Scaling when scrolling down(向下滾動時 ImageView 縮放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的邊界自動更改,帶有內容插圖)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干擾按鈕.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定義、交互式)視圖控制器呈現和解除處理滾動視圖)
主站蜘蛛池模板: 国产yw851.c免费观看网站 | 欧美精品在线播放 | 成人欧美一区二区三区在线播放 | 中文字幕 国产精品 | 日韩一区和二区 | 人人爽日日躁夜夜躁尤物 | 成人在线免费观看av | 国产一区二区三区四区五区加勒比 | 91久久精品国产91久久性色tv | 不卡在线一区 | 97av视频 | h片在线观看免费 | 日韩免费中文字幕 | 成人免费影院 | 婷婷丁香综合网 | 91夜色在线观看 | 午夜影院视频在线观看 | 日韩欧美三区 | 日本黄色一级视频 | 伦理一区二区 | 一区二区三区四区在线免费观看 | 国产成人精品网站 | 欧美日韩在线精品 | 国产一区二区三区在线看 | 91最新在线视频 | 日韩有码一区 | 国产探花| 日韩中文字幕视频 | 欧美成视频 | 久国产视频 | 欧美一区日韩一区 | 国产h在线| 欧美二区乱c黑人 | 中文字幕亚洲精品 | 亚洲+变态+欧美+另类+精品 | 国产精品一区二区久久 | av免费成人 | 中文字幕在线观看视频网站 | 国产精品成人国产乱一区 | 成人精品一区二区三区中文字幕 | 欧美日韩网站 |