当我们将构建更新到IOS 16时,我们注意到当您单击SendMessage_Tapped时,键盘会隐藏一会儿然后重新出现(由于EditorMessage.Focus()触发),这与之前的构建IOS〉=15和任何Android版本不同。
前端代码
<controls:KeyboardFloatFrame
Grid.Row="3"
Style="{StaticResource ChatInputBoxFrameStyle}"
Focused="EditorArea_Focused"
IsVisible="{Binding ShowKeyboardSection}">
<pancakeview:PancakeView
Style="{StaticResource ChatInputBoxPanCakeViewStyle}"
Focused="EditorArea_Focused">
<Grid x:Name="EditorContainerGrid"
Padding="{OnPlatform iOS='10,5,0,5'}"
Focused="EditorArea_Focused"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<controls:ChatEditor x:Name="EditorMessage"
Grid.Column="0"
Text="{Binding Message}"
Focused="EditorMessage_Focused"
Unfocused="EditorMessage_Unfocused" />
<Grid Grid.Column="1"
VerticalOptions="End"
IsVisible="false"
Padding="{OnPlatform iOS='0,0,0,10'}"
x:Name="SendIconGrid"
Opacity="{Binding SendButtonOpacity }"
HorizontalOptions="Fill">
<Image Source="send_icn"
HorizontalOptions="End"
VerticalOptions="End"
Margin="0">
<Image.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1"
Tapped="SendMessage_Tapped" />
</Image.GestureRecognizers>
</Image>
<Grid.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1"
Tapped="SendMessage_Tapped" />
</Grid.GestureRecognizers>
</Grid>
</Grid>
<pancakeview:PancakeView.GestureRecognizers>
<TapGestureRecognizer Tapped="EditorFrameArea_Tapped" />
</pancakeview:PancakeView.GestureRecognizers>
</pancakeview:PancakeView>
</controls:KeyboardFloatFrame>
后端代码
#region Event Handlers
private void SendMessage_Tapped(object sender, System.EventArgs e)
{
KeepFocusOnMessageEditor();
_viewModel.SendMessage.Execute(sender);
}
private void EditorArea_Focused(object sender, System.EventArgs e)
{
KeepFocusOnMessageEditor();
}
private void EditorFrameArea_Tapped(object sender, System.EventArgs e)
{
KeepFocusOnMessageEditor();
}
private void BodyGrid_Tapped(object sender, System.EventArgs e)
{
if (IsIOS)
{
EditorMessage.Unfocus();
}
}
private void EditorMessage_Focused(System.Object sender, FocusEventArgs e)
{
Constants.AndroidFlags.IgnoreFocusChanges = true;
SendIconGrid.IsVisible = true;
}
private void EditorMessage_Unfocused(System.Object sender, FocusEventArgs e)
{
Constants.AndroidFlags.IgnoreFocusChanges = false;
if (_viewModel.Message.IsBlank())
{
SendIconGrid.IsVisible = false;
}
}
#endregion
#region Private Methods
private void ScrollToMessage(ChatMessage message)
{
if (message != null && message.IsUnreadHeaderText && message.MessageStatus != Common.ChatMessageStatus.Read)
{
message.MessageStatus = Common.ChatMessageStatus.Read;
Device.BeginInvokeOnMainThread(() => ListViewChat.ScrollTo(message, ScrollToPosition.End, false));
}
else
{
Device.BeginInvokeOnMainThread(() => ListViewChat.ScrollTo(message, ScrollToPosition.End, false));
}
}
private void KeepFocusOnMessageEditor()
{
if (IsIOS)
{
EditorMessage.Focus();
} else {
Constants.AndroidFlags.IgnoreFocusChanges = true;
Device.BeginInvokeOnMainThread(() => EditorMessage.Focus());
}
}
#endregion
我希望iOS 16的操作方式与其他版本相同,当您单击SendMessage_Tapped图像时,键盘不会隐藏。只是在寻找一种方法,以保持键盘上,如果用户点击图标。
1条答案
按热度按时间c3frrgcw1#
我创建了一个新的示例,并在代码中使用了该条目而不是
controls:ChatEditor
。而且我发现当我点击imageview时键盘并不总是显示。当我在ios15.4上点击图像时,键盘会 Flink 一次,在ios16.0上会隐藏并显示。实际上,默认的行为应该是键盘隐藏一会儿然后重新出现。
根据官方文档关于显示和隐藏原生ios中的键盘,键盘的显示和隐藏依赖于输入视图发送的通知。单击图像视图时,输入视图失去焦点,然后重新获得焦点。所以键盘隐藏了一会儿,然后又出现了。
还有一个关于iOS 16 Keyboard Lagging的问题,你可以看到键盘隐藏并在iOS 16上重新出现是因为键盘的低响应。
此外,如果你想让键盘保持在屏幕上,你需要自定义一个本机输入视图,并覆盖关于失去焦点和发送keyboardWillHideNotification的方法。这是一项艰苦的工作。