美文网首页
鼠标事件

鼠标事件

作者: 开发者老岳 | 来源:发表于2017-12-15 18:40 被阅读11次

    A和B俩视图的关系,B贴在A上。

    A的代码:若把[super mouseDown:event];屏蔽,则B里不会执行-mouseDown:方法。

    - (void)mouseDown:(NSEvent *)event
    {
        [super mouseDown:event];
    }
    
    - (void)mouseUp:(NSEvent *)event
    {
        [super mouseUp:event];
    }
    

    //AppKit 里的 NSControl 默认都是不追踪 mouseMove 事件的,增加这个方法用来激活 mouseMove、mouseEnter、mouseExit等事件追踪

    @interface IPBorderedView ()
    {
        NSTrackingArea *trackingArea;
    }
    @end
    
    @implementation IPBorderedView
    
    - (void)updateTrackingAreas
    {
        [super updateTrackingAreas];
        if (trackingArea){
            [self removeTrackingArea:trackingArea];
            trackingArea=nil;
        }
    
        NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow;
        trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
        [self addTrackingArea:trackingArea];
    }
    

    相关文章

      网友评论

          本文标题:鼠标事件

          本文链接:https://www.haomeiwen.com/subject/pbwdwxtx.html