如何在Xamarin或xcode目标C中的两个不同的ViewController中覆盖触摸事件?

时间:2016-04-04 19:30:47

标签: ios objective-c xamarin xamarin.ios touch

我有两个视图控制器,用触摸事件做不同的事情。它们与简单的segue相连。我重写那样的触摸方法(Xamarin):

public override void TouchesBegan (NSSet touches, UIEvent evt)
{
    base.TouchesBegan (touches, evt);
    UITouch touch = touches.AnyObject as UITouch;
    //my code
}

public override void TouchesMoved(NSSet touches, UIEvent evt)
{
    base.TouchesMoved(touches, evt);
    UITouch touch = touches.AnyObject as UITouch;
    //my code
}

public override void TouchesEnded(NSSet touches, UIEvent evt)
{
    //my code
}

但如果我在第一个ViewController中触摸屏幕,它会在两个ViewControllers中被触发。我怎么能防止这种情况? 这是我的VC课程:

partial class PSViewController : UIViewController
{
    public PSViewController (IntPtr handle) : base (handle)
    {
    }
}
partial class PCViewController : UIViewController
{
    public PCViewController (IntPtr handle) : base (handle)
    {
    }
}

除了触摸事件之外,我在两个VC上都有ViewDidAppear:

public override void ViewDidAppear (bool animated)
{
    base.ViewDidAppear (animated);
}

任何帮助都将不胜感激。

-B

0 个答案:

没有答案