在Xamarin.IOS C#中强制Draw()

问题描述 投票:0回答:1

我正在研究Xamarin.IOS项目,我希望在TouchBegan和UIView的TouchEnd上更新屏幕(通过调用覆盖Draw()方法)。

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

    SetNeedsDisplay();
}

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

    SetNeedsDisplay();
}

public override void Draw(CGRect rect)
{
    //draw in CGContext
}

仅在我点击时第一次从TouchBegan调用Draw()方法。之后,在TouchEnd完成之前,不会调用Draw。

有没有办法在我的TouchBegan上强制Draw(在TouchEnd被触发之前)。与Android中的Invalidate()类似的东西。

这是因为,我在TouchBegan和TouchEnd中绘制了不同的上下文。因此,我希望在每次触摸事件后确定调用Draw方法。

任何帮助表示赞赏。谢谢。

xamarin xamarin.forms xamarin.ios
1个回答
0
投票

TouchesBegan只是在一个或多个手指触摸屏幕时触发。如果你想在触摸屏幕并移动手指时调用Draw方法,请添加方法TouchesMoved

public override void TouchesMoved(NSSet touches, UIEvent evt)
{
    base.TouchesMoved(touches, evt);
    SetNeedsDisplay();
}

然后当你的手指离开UIView时,你可以在TouchesEnded结束你的绘画。

© www.soinside.com 2019 - 2024. All rights reserved.