zoukankan      html  css  js  c++  java
  • Wp8 Popup不随输入法偏移问题解决方案

        在wp中我们经常要实现,浮窗的效果这时我们就会考虑到Popup,但是在用Popup开发我们会遇到一个非常尴尬的问题,由于Popup不在主界面的可视化树内,在Popup显示的位置在输入法面板出现的范围时,输入法面板弹出,不会随之偏移直接被输入法覆盖了。

    在以前wp7.5中我们可以在输入法面板弹出时,去获得根视图的Transform获得偏移的量来偏移我们的Popup,但是在wp8中却没发现这个偏移,没办法只能各种倒腾,最后发现了一个曲线救国的方案(RT框架下)。

    输入法面板消失事件

    void PopupWindow_Hiding(Windows.UI.ViewManagement.InputPane sender, Windows.UI.ViewManagement.InputPaneVisibilityEventArgs args)

    {

        //在输入法面板消失时,将添加的偏移清除

        AnimationManager.Begin(AnimationFactory.Create(HostTransform, "TranslateY"0TimeSpan.FromMilliseconds(100)));

    }

     

    输入法面板弹出事件

    void PopupWindow_Showing(Windows.UI.ViewManagement.InputPane sender, Windows.UI.ViewManagement.InputPaneVisibilityEventArgs args)

    {

        if(IsShow)

    {

        //Showing实在输入法面板开始弹出时触发

        //下面开始记录Window.Current.Content 0,0点相对于屏幕的坐标

            var last = Window.Current.Content.TransformToVisual(null).TransformPoint(new Windows.Foundation.Point(00));

            EventHandler<object> handler = null;//只有InputPane显示事件,只能勉强用LayoutUpdated事件了。。。

        //再注册LayoutUpdated事件接着获取与Window.Current.Content 0,0点相对于屏幕的坐标,与之前获得的坐标对比

            (Window.Current.Content as FrameworkElement).LayoutUpdated += handler= (s, e) =>

                       {

                           //0,0到屏幕的映射current不等于last时,就认为InputPane打开完成^_^

                           var current = Window.Current.Content.TransformToVisual(null).TransformPoint(new Windows.Foundation.Point(00));

                           if(current != last)//发现去之前的坐标不相等,认为已发生偏移,对当前视图添加偏移

                           {

                               current.= current.- last.- InputOffset;

                               (Window.Current.Content as FrameworkElement).LayoutUpdated -= handler;

                               (HostTransform as Windows.UI.Xaml.Media.CompositeTransform).TranslateY = current.Y;

                           }

                       };

        }

    }

  • 相关阅读:
    手机领域的各种角色介绍
    windows配置教程
    windows7安装教程(vmware)
    /etc/profile、~/.bash_profile、~/.bashrc和/etc/bashrc
    vmware自定义网段
    wps去除首字母自动大写
    Windows和Linux创建软链接和硬链接
    计算机的组成部件及其厂商
    windows开机锁定小键盘
    PL/SQL Developer安装教程
  • 原文地址:https://www.cnblogs.com/anye6488/p/3900135.html
Copyright © 2011-2022 走看看