2017-02-27 3 views
3

私はすべてのコンテンツが読み込まれている間の相互作用をブロックするウィンドウのコンテンツの上に配置したいカスタムNSViewを作成しました。私が抱えていた問題は、今では修正されているが、私は以下のコントロールにNSViewをクリックすることができたということです。新しい問題は、私がコントロールをクリックすることができなくても、マウスをテキストコントロールの上に移動すると、マウスがI Beamアイコンに切り替わるということです。Xamarin Macでマウスのバブルをブロックする

どのようにして、NSViewはその下のすべての相互作用を完全にブロックしますか?

私が作成したのNSViewは以下の通りです:

[Register("StupidView")] 
public class StupidView : NSView 
{ 


    public StupidView() 
    { 
     // Init 
     Initialize(); 
    } 

    public StupidView(IntPtr handle) : base (handle) 
    { 
     // Init 
     Initialize(); 
    } 

    [Export("initWithFrame:")] 
    public StupidView(CGRect frameRect) : base(frameRect) { 
     // Init 
     Initialize(); 
    } 

    private void Initialize() 
    { 
     this.AcceptsTouchEvents = true; 
     this.WantsLayer = true; 
     this.LayerContentsRedrawPolicy = NSViewLayerContentsRedrawPolicy.OnSetNeedsDisplay; 
    } 

    public override void DrawRect(CGRect dirtyRect) 
    { 
     var ctx = NSGraphicsContext.CurrentContext.GraphicsPort; 
     ctx.SetFillColor(new CGColor(128, 128, 128, 0.7f)); 
     ctx.FillRect(dirtyRect); 
    } 

    public override void MouseDown(NSEvent theEvent) 
    { 
     if (Hidden) 
     { 
      base.MouseDown(theEvent); 
     } 
    } 

    public override void MouseDragged(NSEvent theEvent) 
    { 

     if (Hidden) 
     { 
      base.MouseDragged(theEvent); 
     } 
    } 

    public override bool AcceptsFirstResponder() 
    { 
     return !this.Hidden; 
    } 

    public override bool AcceptsFirstMouse(NSEvent theEvent) 
    { 
     return !this.Hidden; 
    } 

    public override NSView HitTest(CGPoint aPoint) 
    { 
     return Hidden ? null : this; 
    } 
} 

答えて

2

私は数週間前に同じ問題を抱えていたし、ここで私はこれを管理することができる方法である:

まず、スーパーのユーザーインタラクションを防ぐために以下に置いて、私は唯一のマウスクリックをキャッチすると、あなたは何もする必要はありません場合は、何もしないでいた透明ボタンを追加しました:メートルで、あなたの他の問題については、

private void Initialize() 
{ 
    this.AcceptsTouchEvents = true; 
    this.WantsLayer = true; 
    this.LayerContentsRedrawPolicy = NSViewLayerContentsRedrawPolicy.OnSetNeedsDisplay; 

    //Add button to prevent user interactions 

    NSButton buttonToPreventUserInteraction = new NSButton(); 
    buttonToPreventUserInteraction.Bordered = false; 
    buttonToPreventUserInteraction.Transparent = true; 
    buttonToPreventUserInteraction.TranslatesAutoresizingMaskIntoConstraints = false; 
    AddSubview(buttonToPreventUserInteraction); 

    //If you want to add some constraints on the button, for it to resize and keep the same size of your subview 

    var dicoViews = new NSMutableDictionary(); 
    dicoViews.Add((NSString)"buttonToPreventUserInteraction", buttonToPreventUserInteraction); 
    NSLayoutConstraint[] buttonToPreventUserInteractionHorizontalConstraints = NSLayoutConstraint.FromVisualFormat("H:|[buttonToPreventUserInteraction]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dicoViews); 
    NSLayoutConstraint[] buttonToPreventUserInteractionVerticalConstraints = NSLayoutConstraint.FromVisualFormat("V:|[buttonToPreventUserInteraction]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dicoViews); 
    AddConstraints(buttonToPreventUserInteractionHorizontalConstraints); 
    AddConstraints(buttonToPreventUserInteractionVerticalConstraints); 

} 

を下に配置されたスーパービュー内のコンテンツからカーソルを変更すると、サブビューにNSTrackingAreaを追加し、オーバーライドメソッド "MouseMoved"を実装してカーソルを変更できます。まず

(あなたは「初期化」の方法でこのコードを置くことができます)あなたのサブビューに
NSTrackingAreaOptions opts = ((NSTrackingAreaOptions.MouseMoved | NSTrackingAreaOptions.ActiveInKeyWindow | NSTrackingAreaOptions.InVisibleRect)); 
var trackingArea = new NSTrackingArea(new CGRect(0, 0, FittingSize.Width, FittingSize.Height), opts, Self, null); 

AddTrackingArea(trackingArea); 

をNSTrackingAreaを追加し、オーバーライドメソッド実装

を::

public override void MouseMoved(NSEvent theEvent) 
{ 
    //You can choose the type of cursor you want to use here 
    NSCursor.ArrowCursor.Set(); 
} 
をあなたはこのような何かを行うことができます

これは私のために作った、それもあなたのために願って

+0

追跡エリアはIビームの問題に亀裂、ありがとう – bizzehdee

関連する問題