[英]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.