处理大于其父视图的子视图的触摸
问题描述:
假设我制作了一个包含另一个UIImageView的UIImageView。但是子视图比第一个视图大。处理大于其父视图的子视图的触摸
绿色子视图是显著大于它是上海华,黑色方块。如果我触摸左上方只有黑色方块,我会得到“touchbegan image1”,这正是我所期望的。如果我触摸黑色方块和绿色方块重叠的区域,我会得到“touchbegan image1”和“touchbegan image2”,这是我所期望的。 这里是我的问题:如果我触摸只有绿色方块存在的黑色方框外的区域,我没有输出。所以TouchesBegan既不是image1也不是image2。在这种情况下,当我仅触摸绿色矩形,同时仍将image2(绿色)作为image1(黑色)的子视图时,我希望TouchesBegan被称为image2(绿色)。那可能吗?
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);
}
答
这是因为您将它添加为image1的子项。 Image1在其绑定/框架内侦听触摸并将其发送给其子(如果有的话)。 image2可能更大,但它的touchlistener来自image1 frame touch。
谢谢。所以我问的是故意不可能的? – LampShade 2013-02-09 15:07:00