1

我小时候有一个简单的 iPhone 应用程序,它有一个简单的视图和一个自定义视图。孩子只是画在主视图上的一个正方形。

我需要跟踪进入此子视图但从视图外部开始的触摸的触摸事件。

到目前为止,我尝试将 TouchesBegin/TouchesMoved 事件添加到父视图。还尝试将 直接添加到子控件,但这不会跟踪未在该控件中启动的任何触摸。

问题是:

a) 我能以某种方式从 Position 获得控制权吗?

b)这是最好的方法,还是有其他方法?

再次,我为我正在尝试移植的游戏添加了这个 GamePlay 视频(在我的业余时间)。这不是促销尝试,而是说明了我正在努力实现的目标。我编写了游戏的 Win8 和 WP7 版本,所以我不想在这里复制其他人的工作。:) 如果您不想知道它是什么游戏,请不要观看。不看这个问题仍然有效。

http://www.youtube.com/watch?v=13IczvA7Ipo

谢谢

//约翰

4

1 回答 1

1

I stumbled on the answer myself. In the parent I override TouchesMoved (and Begin and Ended not shown here).

I then iterate the subviews and chech if it's the view I'm looking for by type and then check if the Frame contains the point. The code below is just concept of course.

    public override void TouchesMoved (NSSet touches, UIEvent evt)
    {
        base.TouchesMoved (touches, evt);

        UITouch touch = touches.AnyObject as UITouch;

        if (touch != null) {
            var rp = touch.LocationInView (touch.View);

            foreach(var sv in this.View.Subviews)
            {
                if(!(sv is LetterControl))
                    continue;

                if(sv.Frame.Contains (rp))
                {
                    Console.WriteLine("LetterControl found");
                }
            }
        }
    }
于 2012-11-19T08:14:02.347 回答