NSScrollView在另一个NSScrollView中 [英] NSScrollView inside another NSScrollView

查看:65
本文介绍了NSScrollView在另一个NSScrollView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSScrollview 嵌套在另一个 NSScrollview 内。我如何使内视图仅处理水平滚动?垂直滚动应可移动外部视图。

I have a NSScrollview nested inside another NSScrollview. How do i make the inner view handle horizontal scrolling only? Vertical scrolling should move the outer view.

当前,我将 scrollWheel:事件从内部传递给外部视图视图,但是它非常慢。

Currently i pass the scrollWheel: event to the outer view from the inner view, but it is very slow.

推荐答案

我还遇到了嵌套滚动视图的问题。内部滚动视图应该水平滚动,而外部滚动视图应该垂直滚动。

I also had the problem of nested scroll views. The inner scroll view should scroll horizontally, and the outer should scroll vertically.

在处理来自魔术鼠标/触控板的滚动事件时,仅选择一个滚动条非常重要每个手势的视图,否则当手指不能完全笔直移动时,您会看到奇怪的抽搐。您还应该确保用两根手指轻敲触控板会显示两个滚动条。

When handling scroll events from magic mouse / trackpad, it is important to pick only one of the scroll views for each gesture, otherwise you will see odd jerking when your fingers don't move perfectly straight. You should also ensure that tapping the trackpad with two fingers shows both scrollers.

在处理强大鼠标或老式滚动轮鼠标的旧滚动事件时,必须选择每个事件都使用右滚动视图,因为事件中没有手势阶段信息。

When handling legacy scroll events from mighty mouse or mice with old fashioned scroll wheels, you must pick the right scroll view for each event, because there is no gesture phase information in the events.

这是我的内部滚动视图的子类,仅在Mountain Lion中进行了测试:

This is my subclass for the inner scroll view, tested only in Mountain Lion:

@interface PGEHorizontalScrollView : NSScrollView {
    BOOL currentScrollIsHorizontal;
}
@end

@implementation PGEHorizontalScrollView
-(void)scrollWheel:(NSEvent *)theEvent {
    /* Ensure that both scrollbars are flashed when the user taps trackpad with two fingers */
    if (theEvent.phase==NSEventPhaseMayBegin) {
        [super scrollWheel:theEvent];
        [[self nextResponder] scrollWheel:theEvent];
        return;
    }
    /* Check the scroll direction only at the beginning of a gesture for modern scrolling devices */
    /* Check every event for legacy scrolling devices */
    if (theEvent.phase == NSEventPhaseBegan || (theEvent.phase==NSEventPhaseNone && theEvent.momentumPhase==NSEventPhaseNone)) {
        currentScrollIsHorizontal = fabs(theEvent.scrollingDeltaX) > fabs(theEvent.scrollingDeltaY);
    }
    if ( currentScrollIsHorizontal ) {
        [super scrollWheel:theEvent];
    } else {
        [[self nextResponder] scrollWheel:theEvent];
    }
}
@end

我的实现并不总是正确转发手势取消事件,但至少在10.8中不会造成问题。

My implementation does not always forward Gesture cancel events correctly, but at least in 10.8 this does not cause problems.

这篇关于NSScrollView在另一个NSScrollView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆