我将如何在 CATiledLayer 上捕获触摸事件?
我有以下情况,如果我将视图层更改为 CATiledLayer,视图将停止捕获 TouchesXXX 事件。为什么会发生这种情况,我应该如何解决这个问题。
public partial class DocumentView : UIView
{
public DocumentView ()
{
//if the following lines are removed touch events are captured
//otherwise they are not
var tiledLayer = Layer as CATiledLayer;
tiledLayer.Delegate = new TiledLayerDelegate (this);
}
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
//does not get called if we hook TiledLayerDelegate up there in the construct
base.TouchesBegan (touches, evt);
}
}
public class TiledLayerDelegate : CALayerDelegate
{
public DocumentView DocumentView;
public TiledLayerDelegate (DocumentView documentView)
{
DocumentView = documentView;
}
public override void DrawLayer (CALayer layer, CGContext context)
{
//draw happens here
}
}