现在的位置: 首页 > 综合 > 正文

mono touch中touch触发对象判断

2013年07月31日 ⁄ 综合 ⁄ 共 1012字 ⁄ 字号 评论关闭

先看一段代码:

        public override void TouchesBegan (NSSet touches, UIEvent evt)
        {
            base.TouchesBegan (touches, evt);
            
            UITouch touch = touches.AnyObject as UITouch;
            
            if (touch != null) {
                PointF pt = touch.LocationInView (this);
                
                if (_path.ContainsPoint (pt, true)) {
                    Title = "You touched the square";
                } else {
                    Title = "You didn't touch the square";
                }
            }
        }

粗体红色部分是我们的待触发对象(派生至NSOjbect对象),如果当前触发的点(point)是在我们的目标对象内部就表明接触对象。除此之外还定义了几个虚函数用来处理

触碰事件:

public class UIResponder :NSObject
        {
            //...
            public virtual void TouchesBegan (NSSet touches, UIEvent evt);
            public virtual void TouchesMoved (NSSet touches, UIEvent evt);
            public virtual void TouchesEnded (NSSet touches, UIEvent evt);
            public virtual void TouchesCancelled (NSSet touches, UIEvent evt);
            //...
        }

抱歉!评论已关闭.