如何将滚动事件传递到父NSScrollView [英] How to pass scroll events to parent NSScrollView

查看:498
本文介绍了如何将滚动事件传递到父NSScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个更大的滚动窗口内固定大小的NSTextViews。 IB要求文本视图在其自己的NSScrollViews中,即使它们的最小/最大大小是固定的,因此它们实际上不会滚动。当跟踪板手势在textview框架内(不管它们是否具有焦点),它们被文本视图的scrollview捕获,所以什么也没有发生。

I need fixed-size NSTextViews inside a larger scrolling window. IB requires that the textviews be inside their own NSScrollViews, even though their min/max sizes are fixed so that they won’t actually scroll. When trackpad gestures are made within the textview frames (regardless of whether they have focus), they are captured by the textviews’ scrollviews, so nothing happens.

如何告诉文本视图的滚动视图将滚动事件传递到窗口的主滚动视图? (或者我应该问我如何告诉窗口的主要scrollview来处理这些事件本身,而不将它们传递给它的子scrollview。)

How do I tell the textviews’ scrollviews to pass scroll events up to the window’s main scrollview? (Or perhaps I should be asking how I tell the window’s main scrollview to handle these events itself and not pass them on to its child scrollviews.)

IB结构是


  • 视窗

    • 视窗的内容视图

      • 窗口的大滚动视图(滚动事件的所需目标)



          • 内容视图在单独的xib

            • scrollview的textview

              • textview

              • 推荐答案

                这真的很尴尬。经过几个星期的推迟,我做了第一次尝试获得一个子类NSScrollView的行为被动 - 这证明是一个没有脑子。

                This is really embarrassing. After weeks of putting it off, I made a first attempt to get a subclassed NSScrollView to behave passively — and it turned out to be a no brainer.

                这是子类:

                h文件:

                #import <Cocoa/Cocoa.h>
                
                @interface ScrollViewPassive : NSScrollView {
                
                // This property is assigned a ref to windowController’s main scrollview.
                NSScrollView *svActive; 
                
                }
                
                @property (nonatomic, retain) NSScrollView *svActive;
                
                @end
                

                m文件:

                #import "ScrollViewPassive.h"
                
                @implementation ScrollViewPassive
                
                @synthesize svActive;
                
                // Pass any gesture scrolling up to the main, active scrollview.
                - (void)scrollWheel:(NSEvent *)event {
                    [svActive scrollWheel:event];
                }
                
                @end
                

                对于这些被动滚动视图;在他们的xibs被指定为NSBox的内容之后,我给他们的主要scrollview的参考:

                There’s no need to make outlets for these passive scrollviews; I give them their refs to the main scrollview right after their xibs are assigned as content to the NSBox:

                    [self.boxDisplayingTextViews setContentView:self.subviewCtllr1.view];
                    // A textview's superview's superview is its scrollview:    
                    ((ScrollViewPassive *)[[self.subviewCtllr1.textview1 superview] superview]).svActive = self.scrollviewMain;
                

                就是这样。像一个魅力。

                That’s it. Works like a charm.

                这篇关于如何将滚动事件传递到父NSScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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