UIAlertView
を使用しないことを強くお勧めします。
使用UIAlertController
代わりに、それはiOS8/9月10日に利用可能であり、適切なUIViewController
のように機能し、UIAlertControllerStyle.Alert
スタイルで使用し、それを使用しているときにMotionBegan/MotionEnded
に問題を持っていないときに、古いアラートのように見えます。
のであなたはUIViewController
のそれぞれにMotionBegan/MotionEnded
を上書きするか:自分のUIWindowのサブクラスを作成
public override void MotionBegan(UIEventSubtype motion, UIEvent evt)
{
Console.WriteLine("MotionBegin");
base.MotionBegan(motion, evt);
}
public override void MotionEnded(UIEventSubtype motion, UIEvent evt)
{
Console.WriteLine("MotionEnded");
base.MotionEnded(motion, evt);
}
それともと、したがって、あなたがグローバルモーションイベントを取得します(あなただけの(PostNotificationName
を投稿することができます)を経由してアプリの他の領域がモーションイベントに応答する必要がある場合は通知センターに送信してください。
public class ShakeWindow : UIWindow
{
public ShakeWindow() : base() { }
public ShakeWindow(IntPtr handle) : base(handle) { }
public override void MotionBegan(UIEventSubtype motion, UIEvent evt)
{
Console.WriteLine("Window MotionBegin");
NSNotificationCenter.DefaultCenter.PostNotificationName("ShakeMe", this);
base.MotionBegan(motion, evt);
}
public override void MotionEnded(UIEventSubtype motion, UIEvent evt)
{
Console.WriteLine("Window MotionEnded");
base.MotionEnded(motion, evt);
}
}
UIAlertController
使用例NSNotificationCenter
:
var button2 = new UIButton(UIButtonType.RoundedRect);
button2.SetTitle("Alert 2", UIControlState.Normal);
button2.Frame = new CGRect(20, 60, 100, 40);
button2.TouchUpInside += (object sender, EventArgs e) =>
{
var alert2 = UIAlertController.Create("StackOverflow", "Shake me now", UIAlertControllerStyle.Alert);
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("ShakeMe"), (obj) =>
{
alert2?.DismissViewController(true, null);
});
alert2.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
{
alert2.DismissViewController(true, null);
}));
PresentViewControllerAsync(alert2, true);
};
Add(button2);
素晴らしい!早速のお返事ありがとうございます。代わりにUIAlertControllerを使用します。 UIAlertViewsを使用する理由は、ユーザーの中にはまだiOS 7があるため、UIAlerViewControllerを表示できないことが挙げられます。しかし、このスクリーンショット機能は内部テストのための機能なので、アラートを表示するときにOSのバージョンを確認するだけです。とにかくUIAlertViewControllersを実装する必要があります:-) – stonecompass
@Hypo:iOS7(+)でアラートをサポートする必要がある場合は、カスタムUIViewControllerを作成してAlert-lookを再現します。と幸せなXammieコーディング... – SushiHangover
本当に、ありがとう! – stonecompass