自定义ScrollView,如何让NSView setFrame: 更快?
我正在制作自己的 ScrollView。 这是我用于使用鼠标滚轮或触摸板滚动的代码 但它的工作并不完美。它有点滞后。
- (void) scrollWheel:(NSEvent *)theEvent
{
NSRect rect = [contentView frame];
rect.origin.x += [theEvent deltaX];
rect.origin.y += [theEvent deltaY];
[contentView setFrame:rect];
}
当我对图层执行相同的操作(用于测试)时,效果会更好。
[CATransaction setDisableActions:YES];
[CATransaction begin];
[contentView layer].frame = newRect;
[CATransaction commit];
如何让setFrame完美工作?
I am making my own ScrollView.
here is the code i use for scrolling with mouse wheel or touchpad
but it doesn't work flawless. it lags a bit.
- (void) scrollWheel:(NSEvent *)theEvent
{
NSRect rect = [contentView frame];
rect.origin.x += [theEvent deltaX];
rect.origin.y += [theEvent deltaY];
[contentView setFrame:rect];
}
when i do the same with layers (for test) it works much better.
[CATransaction setDisableActions:YES];
[CATransaction begin];
[contentView layer].frame = newRect;
[CATransaction commit];
how to make setFrame work flawless?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在努力研究苹果在 NSScrollView 中是如何做到这一点的。答案是他们进行高性能绘图 - 仅更改部分,而不是通常完成的整个视图。
之后我决定自定义标准滚动视图和标准滚动条。
I was looking hard, on how it is done by apple in NSScrollView. and the answer is that they make high performance drawing - only the changed parts, not the whole view as it is usually done.
After that i decided to customize the standard scrollView and standard scrollers.