【问题标题】:How to create custom keyboard in xamarin iOS?如何在 xamarin iOS 中创建自定义键盘?
【发布时间】:2019-08-22 09:27:06
【问题描述】:

我已经使用自定义键盘实现了跨平台应用程序,我需要为 xamarin IOS 调度键盘事件,下面的代码我可以在 xamarin Android 上调度事件。

webView.DispatchKeyEvent(new KeyEvent(0, 0, KeyEventActions.Down, KeyEvent.KeyCodeFromString(digit), 0, MetaKeyStates.ShiftLeftOn | MetaKeyStates.CtrlOn));
webView.DispatchKeyEvent(new KeyEvent(0, 0, KeyEventActions.Up, KeyEvent.KeyCodeFromString(digit), 0, MetaKeyStates.ShiftLeftOn | MetaKeyStates.CtrlOn));

我需要获得 xamarin iOS 的等价物。如果您知道,请告诉我。

【问题讨论】:

    标签: c# xamarin xamarin.forms xamarin.android xamarin.ios


    【解决方案1】:

    您可以创建内容页面的自定义渲染器,它会延续 webview 并添加键盘事件。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using xxx.iOS;
    using Foundation;
    using UIKit;
    using ObjCRuntime;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly:ExportRenderer(typeof(ContentPage),typeof(MyPageRenderer))]
    namespace xxx.iOS
    {
        public class MyPageRenderer:PageRenderer
        {
            public override void ViewWillAppear(bool animated)
            {
                base.ViewWillAppear(animated);
    
                NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("KeyboardWillShow"), new NSString("UIKeyboardWillShowNotification"), null);
    
                NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("KeyboardWillHide"), new NSString("UIKeyboardWillHideNotification"), null);
            }
    
            [Export("KeyboardWillShow")]
            void KeyboardWillShow()
            {
    
            }
    
            [Export("KeyboardWillHide")]
            void KeyboardWillHide()
            {
    
            }
    
        }
    }
    

    【讨论】:

    • 嗨 Lucas Zhang,我需要调度一个关键事件,比如 android。在 android 中,我确实从自定义键盘发送了一个键并在键事件中调度。
    • Entry 有一个名为 TextChanged 的事件。当此 Entry 元素中的文本发生更改时会引发该事件。您可以在事件中获取您输入的值并处理逻辑。
    猜你喜欢
    • 2022-09-23
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    相关资源
    最近更新 更多