【问题标题】:Monotouch Events单点触控事件
【发布时间】:2011-11-07 00:46:44
【问题描述】:

我正在尝试使用 MonoTouch 运行以下代码:

this.TouchesBegan += delegate { txtAmount.ResignFirstResponder(); };

编译时出现以下错误:

Cannot assign to `TouchesBegan' because it is a `method group'

API 似乎支持这一点:http://docs.xamarin.com/ios/advanced_topics/api_design

有什么想法吗?

【问题讨论】:

  • 除了 poupou 的回答,如果你想使用 TouchesBegan 方法,你必须继承 UIView (或任何你想使用的类的 TouchesBegan 方法)并覆盖它。
  • 原来 UIViewController 也暴露了相同的方法,所以我简单地覆盖了它。

标签: c# ios events xamarin.ios uigesturerecognizer


【解决方案1】:

我猜你使用的是UIGestureRecognizer 对吧?

如果是这样,那么 `TouchesBegan' 是一个方法而不是一个事件,所以你不能给它分配一个代理。

    public virtual void TouchesBegan (NSSet touches, UIEvent evt)

你可能想看看:

    public UITouchEventArgs ShouldReceiveTouch;
    public UIGesturesProbe ShouldRecognizeSimultaneously;
    public UIGestureProbe ShouldBegin;

还有Touches_GestureRecognizers 示例。

【讨论】:

  • 不敢相信我忽略了这一点。谢谢!
猜你喜欢
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
相关资源
最近更新 更多