gpt4 book ai didi

c# - UINavigationBar 在键盘打开时被推出屏幕(UITextView)

转载 作者:行者123 更新时间:2023-11-29 13:55:15 34 4
gpt4 key购买 nike

描述:我得到了一个简单的UIViewController,它只包含一个大的UITextView。有 4 个简单的约束:顶部、右侧、底部和左侧。没什么特别的。

我的问题是什么:当用户开始向 UITextView 中键入文本时,keyboard 打开并且 UINavigationBar 离开屏幕。我希望 UINavigationBar 保持在同一个位置。

演示:

  • UIViewController 的 背景是蓝色
  • UITextView 的 背景是红色
  • 请注意,当 keyboard 第一次出现在 时,一切似乎都很好,但随后出现了 UINavigationBar 问题...<

编辑:

这是一个演示项目:https://drive.google.com/file/d/1lMtXNWLyEXDQMy7eeyu-sQrmsTja-tvO/view?usp=sharing

demo

最佳答案

您可以安装 Xamarin.IQKeyboardManager从你的 iOS 项目上的 Nuget。然后在 AppDelegate 中启用它:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
//...

IQKeyboardManager.SharedManager.Enable = true;

return true;
}

更新:

我没有使用stroryboard创建了一个demo,你可以引用。

在 AppDelegate 中

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// create a new window instance based on the screen size
Window = new UIWindow(UIScreen.MainScreen.Bounds);
Window.RootViewController = new UINavigationController(new MainViewController());
IQKeyboardManager.SharedManager.Enable = true;

// make the window visible
Window.MakeKeyAndVisible();

return true;
}

in MainViewController

public override void ViewDidLoad()
{
View = new UniversalView();

base.ViewDidLoad();

Title = "Title";

IQTextView textView = new IQTextView() {

Frame = new CGRect(20, 90, UIScreen.MainScreen.Bounds.Width - 40, 626),
BackgroundColor = UIColor.Red,
Text = "xxx",
Font = UIFont.SystemFontOfSize(14),
};

View.AddSubview(textView);

// Perform any additional setup after loading the view
}

您的问题可能是因为您使用了自动布局。你可以使用 Masonry来自 Nuget。

关于c# - UINavigationBar 在键盘打开时被推出屏幕(UITextView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56802689/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com