我写了自定义控件:
public class ExtendedImage : View
{
public string SourceStart { get; set; }
public string SourceComplete { get; set; }
}
当我在我的pcl项目中使用它时,我添加了tapGestureRecognizer。此识别器具有可绑定命令:
var image = new ExtendedImage()
{
SourceStart = "im1.png"),
SourceComplete = "im2.png"),
};
var tap = new TapGestureRecognizer();
tap.SetBinding(TapGestureRecognizer.CommandProperty, "imageCommand");
image.GestureRecognizers.Add(tap);
我有ImageRenderer:
public class iOSImageRenderer : ViewRenderer<ExtendedImage, UIImageView>
{
UIImageView image { get; set; }
string SourceStart { get; set; }
string SourceComplete { get; set; }
protected override void OnElementChanged(ElementChangedEventArgs<ExtendedImage> e)
{
base.OnElementChanged(e);
if(e.OldElement != null || this.Element == null)
return;
SourceStart = Element.SourceStart;
SourceComplete = Element.SourceComplete;
image = new UIImageView(UIImage.FromFile(SourceStart));
image.UserInteractionEnabled = true;
SetNativeControl(image);
}
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
UITouch touch = touches.AnyObject as UITouch;
if(touch != null)
{
image.Image = UIImage.FromFile(SourceComplete);
}
}
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
UITouch touch = touches.AnyObject as UITouch;
if(touch != null)
{
image.Image = UIImage.FromFile(SourceStart);
}
}
}
可绑定识别器不适用于此解决方案。我有相同的windowsPhone渲染器,它的工作完美。对于Android我还没有检查。 我如何在ios渲染器中绑定此命令,或者如何解决此问题?
答案 0 :(得分:0)
我怀疑你的TouchesBegan
/ TouchesEnded
妨碍了UITapGestureRecognizer
。
您应首先修复TouchesEnded
实施,以便调用base.TouchesEnded
而不是base.TouchesBegan
。