該博客介紹瞭如何執行shake to undo,但是我想創建某種基類(在Xamarin形式)的,我可以重複使用此代碼:如何在Xamarin Forms中實現iOS「搖動以撤消」,僅在蘋果設備上?
#region respond to shaking (OS3+)
public override bool CanBecomeFirstResponder {
get {
return true;
}
}
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
this.BecomeFirstResponder();
}
public override void ViewWillDisappear (bool animated)
{
this.ResignFirstResponder();
base.ViewWillDisappear (animated);
}
public override void MotionEnded (UIEventSubtype motion, UIEvent evt)
{
Console.WriteLine("Motion detected");
if (motion == UIEventSubtype.MotionShake)
{
Console.WriteLine("and was a shake");
// Do your application-specific shake response here...
Update();
}
}
#endregion
我不知道在哪裏開始......創建一個僅適用於iOS的基類。
是否有任何種類的依賴注入我可以使用XamarinForms爲所有視圖的基類的運行時實現?
你可以創建一個通用的BasePage類,所有的頁面都繼承自它們,並且它們使用自定義渲染器在iOS上添加晃動行爲 – Jason
你在哪裏實現Shake To Undo?它默認爲iOS的'Xamarin.Forms.Entry'控件實現。 –
@BrandonMinnick期望的效果是爲所有其他情況創建此彈出窗口:''你想提交一個錯誤報告嗎?'' – LamonteCristo