【问题标题】:How to add subview above the keyboard in monotouch/Xamarin.Ios?如何在 monotouch/Xamarin.Ios 中的键盘上方添加子视图?
【发布时间】:2013-08-19 20:15:01
【问题描述】:

如何在 monotouch/Xamarin.Ios 的键盘顶部添加 UIView?

我尝试了以下方法,但似乎不起作用。

UIApplication.SharedApplication.Delegate.Window.AddSubview (myView);
UIApplication.SharedApplication.Delegate.Window.BringSubviewToFront (myView);

UIView 添加在键盘后面。

在 Objective c 中,我能够使用以下代码并且它工作正常。

[[[[UIApplication sharedApplication] windows] objectAtIndex:1] addSubview:myView];

谢谢。

【问题讨论】:

    标签: c# iphone ios uiview xamarin.ios


    【解决方案1】:

    您首先需要创建一个与状态栏处于同一级别的新 UIWindow。您可以将此代码放在 ViewDidLoad 覆盖中:

    newWindow = new UIWindow (UIScreen.MainScreen.Bounds);
    newWindow.WindowLevel = UIWindow.LevelStatusBar;
    

    然后将您的视图(在本例中为按钮)添加到新的 UIWindow:

    var uIButton = new UIButton (UIButtonType.InfoDark) {
        Frame = new RectangleF (10, 400, 30, 30)
    };
    newWindow.AddSubview (uIButton);
    

    在 UITextField 中,为 EditingDidBegin 添加一个事件监听器

    MyInput.EditingDidBegin += (object sender, EventArgs e) => {
        newWindow.Hidden = false;
    };
    

    【讨论】:

      【解决方案2】:

      这对我有用。

      UIApplication.SharedApplication.Windows[1].AddSubview(myView);
      

      【讨论】:

        猜你喜欢
        • 2016-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多