Ios 显示键盘后调整UI大小。尺寸和尺寸问题

Ios 显示键盘后调整UI大小。尺寸和尺寸问题,ios,ios7,xamarin.ios,Ios,Ios7,Xamarin.ios,我想在键盘出现后调整UIView(例如TextField、UIGridView等)的大小。获取适当的事件不是问题所在。我通过计算delta来缩小视图,这取决于键盘的高度 如果我的iPad在肖像模式下摆在面前,所有的计算都会按预期进行。但如果我的设备处于横向模式或倒置模式,我真的很难获得正确的尺寸!某些图幅/边界未转换(在横向模式下,高度仍高于宽度)。其他视图的转换取决于我是否已在横向模式下启动我的应用程序。下一个挑战是使用一致的尺寸度量。有时尺寸与真实像素相似(对于新的iPad2048),有时不

我想在键盘出现后调整UIView(例如TextField、UIGridView等)的大小。获取适当的事件不是问题所在。我通过计算delta来缩小视图,这取决于键盘的高度

如果我的iPad在肖像模式下摆在面前,所有的计算都会按预期进行。但如果我的设备处于横向模式或倒置模式,我真的很难获得正确的尺寸!某些图幅/边界未转换(在横向模式下,高度仍高于宽度)。其他视图的转换取决于我是否已在横向模式下启动我的应用程序。下一个挑战是使用一致的尺寸度量。有时尺寸与真实像素相似(对于新的iPad2048),有时不考虑比例因子(对于新的iPad1024)

还有没有其他办法来调整正确的框架尺寸?或者是否有任何助手能够识别当前方向并为我提供有效尺寸

我当前实现预期行为的代码如下:

MyViewController

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    // My code...

    AppDelegate.CurrentDelegate.KeyboardAppeared += KeyboardAppeared;
    AppDelegate.CurrentDelegate.KeyboardDisappeared += KeyboardDisappeared;
}

public override void ViewWillDisappear(bool animated)
{
    base.ViewWillDisappear(animated);

    AppDelegate.CurrentDelegate.KeyboardAppeared -= KeyboardAppeared;
    AppDelegate.CurrentDelegate.KeyboardDisappeared -= KeyboardDisappeared;
}
private void KeyboardAppeared(object sender, KeyboardEventArgs e)
{
    if (_keyboardButton != null)
        _keyboardButton.Enabled = true;

    var frame = LayoutHelper.RectangleForKeyboardAppearance(_textField, View.Window, e.Height);
    LayoutHelper.ResizeViewForKeyboard(_textField, frame);
}

private void KeyboardDisappeared(object sender, EventArgs e)
{
    if (_keyboardButton != null)
        _keyboardButton.Enabled = false;

    var frame = View.Bounds;
    LayoutHelper.ResizeViewForKeyboard(_textField, frame);
}
MyHelperClass

public static RectangleF RectangleForKeyboardAppearance(UIView view, float windowHeight, float keyboardHeight)
{
    var topOfKeyboard = windowHeight - keyboardHeight; // Obere linke Ecke der Tastatur auf den Bildschirm bezogen
    var viewHeightWindow1 = view.ConvertPointFromView(new PointF(0, topOfKeyboard), null);
    var frame = new RectangleF(view.Frame.X, view.Frame.Y, view.Frame.Width, (viewHeightWindow1.Y + view.Bounds.Y));


    return frame;
}

public static void ResizeViewForKeyboard(UIView view, RectangleF frame)
{
    UIView.BeginAnimations("viewMovementForKeyboard");
    UIView.SetAnimationBeginsFromCurrentState(true);
    UIView.SetAnimationDuration(0.3f);
    view.Frame = frame;
    UIView.CommitAnimations();
}