【发布时间】: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