【问题标题】:Handling touches for a subview that's larger than its parent view处理大于其父视图的子视图的触摸
【发布时间】:2013-02-08 22:40:28
【问题描述】:

假设我创建了一个包含另一个 UIImageView 的 UIImageView。但是 SubView 比第一个视图大。

绿色子视图明显大于它的父视图,黑色方块。如果我触摸只有黑色方块的左上角,我会得到“touchbegan image1”,这是我所期望的。如果我触摸黑色方块和绿色方块重叠的区域,我会得到“touchbegan image1”和“touchbegan image2”,这是我所期望的。 这是我的问题:如果我触摸仅存在绿色方块的黑色方块框之外的区域,我将没有输出。因此,既不为 image1 也不为 image2 调用 TouchesBegan。在这种情况下,我希望在仅触摸绿色矩形时为 image2(绿色)调用 TouchesBegan,同时仍将 image2(绿色)保持为 image1(黑色)的子视图。这可能吗?

    MyImage image1 = new MyImage(new RectangleF(0,0,200,200), "image1");
    image1.BackgroundColor = UIColor.Black;
    this.View.AddSubview(image1);

    MyImage image2 = new MyImage(new RectangleF(50,50,500,500), "image2");
    image2.BackgroundColor = UIColor.Green;
    image1.AddSubview(image2);




public class MyImage : UIImageView
{

    public MyImage ( RectangleF frame, string _Name ) : base(frame)
    {
        Name = _Name;
        UserInteractionEnabled = true;
    }


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

        Console.WriteLine("touchbegan " + Name);
    }

【问题讨论】:

    标签: c# xamarin.ios touch subview touchesbegan


    【解决方案1】:

    这是因为您将其添加为 image1 的子项。 Image1 侦听其绑定/框架内的触摸并将其发送给其子项(如果有)。 image2,可能更大,但它的touchlistener来自image1 frame touch。

    【讨论】:

    • 谢谢。所以我要问的是故意不可能的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-15
    • 2016-08-14
    • 2012-07-31
    • 1970-01-01
    相关资源
    最近更新 更多