[英]AVFoundation Issue With Core Animation on Mac OS X 10.7 Lion
[英]Disable scrolling animation in a WebView in Mac OS X Lion?
當您使用箭頭鍵在Mac OS X Lion中的WebView中導航時,如何禁用發生的動畫?
我試圖更改的行為似乎是Mac OS X Lion上WebViews的默認行為。 如果將文檔加載到WebView中,請設置插入點,然后使用向上箭頭鍵和向下箭頭鍵進行導航,滾動不是即時的 - 有動畫(視圖可以向上或向下滾動)。
這是一個Xcode項目,您可以使用它來查看此行為(只需運行應用程序,在文檔中設置插入點,然后使用向上箭頭和向下箭頭鍵進行導航以使視圖滾動): http:// dl。 dropbox.com/u/78928597/WebViewTest.zip
我想要實現的行為就是在Safari中發生的事情。 如果在Safari中打開其contenteditable
屬性設置為true
的html文檔,則可以在文檔中設置插入點,然后使用向上箭頭鍵和向下箭頭鍵進行導航。 以這種方式導航時,滾動不是動畫。 視圖即時滾動。
這是一個html文檔,您可以使用它來查看此行為: http : //dl.dropbox.com/u/78928597/WebViewTest.html
由於Safari使用WebView,並且它即時滾動,似乎應該有一種方法來改變任何WebView的滾動行為,但我沒有找到它的運氣。
請注意,您需要在使用箭頭鍵導航之前設置插入點,否則您將看到不同的行為。
我認為有一種方法可以做到這一點,但它需要使用Objective-C運行時來修改私有類的私有方法。
要使用Objective-C運行時,請添加
#import <objc/runtime.h>
到Xcode項目中AppDelegate.m頂部的#import
指令。
滾動動畫似乎發生在私有方法中
- (BOOL)_scrollTo:(const CGPoint *)pointRef animate:(NSInteger)animationSpecifier flashScrollerKnobs:(NSUInteger)knobFlashSpecifier
NSClipView
。
我們不能通過子類化WebClipView
由WebView
管理的NSClipView
對象(實際上是私有類WebClipView
的實例)。 相反,我們可以使用一種稱為方法調配的技術。
在AppDelegate
類的@implementation
中,添加
static BOOL (*kOriginalScrollTo)(id, SEL, const CGPoint *, NSInteger, NSUInteger);
static BOOL scrollTo_override(id self, SEL _cmd, const CGPoint *pointRef, NSInteger animationSpecifier, NSUInteger knobFlashSpecifier)
{
return kOriginalScrollTo(self, _cmd, pointRef, 2, knobFlashSpecifier);
}
+ (void)load
{
SEL selector = @selector(_scrollTo:animateScroll:flashScrollerKnobs:);
id WebClipViewClass = objc_getClass("WebClipView");
Method originalMethod = class_getInstanceMethod(WebClipViewClass, selector);
kOriginalScrollTo = (void *)method_getImplementation(originalMethod);
if(!class_addMethod(WebClipViewClass, selector, (IMP)scrollTo_override, method_getTypeEncoding(originalMethod))) {
method_setImplementation(originalMethod, (IMP)scrollTo_override);
}
}
你可以在Mike Ash的文章“樂趣和利潤的方法替換”中閱讀更多關於這里發生的事情的內容; 我正在使用“直接覆蓋”方法調配。
作為此代碼的結果,將調用scrollTo_override()
而不是WebClipView
方法-[_scrollTo:animateScroll:flashScrollerKnobs:]
。 所有scrollTo_override()
都調用原始的-[_scrollTo:animateScroll:flashScrollerKnobs:]
其中2為animationSpecifier
。 這似乎阻止了滾動動畫的發生。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.