Scroll editor in Xamarin Forms into view

前端 未结 6 1275
天涯浪人
天涯浪人 2021-02-02 01:49

Using Xamarin Forms, consider the Xaml below.


   

        
6条回答
  •  Happy的楠姐
    2021-02-02 02:11

    Expanding on the answer from @Falko, you can check the platform for iOS since Android handles this as expected natively.

    I also added this to the page for quick and dirty orientation via this answer.

    static bool IsPortrait(Page p) { return p.Width < p.Height; }
    

    Anyway, I understand that Xamarin are adding some solutions for this soon. For now, though...

    protected async void Message_Focused(object sender, EventArgs args)
    {
        if (Device.OS == TargetPlatform.iOS)
        {
            //TLR: still need a way to determine the iOS keyboard's height first
            //until then, this is a functional hack
    
            if (IsPortrait(this))
            {
                KeyboardSpacer.HeightRequest = 165;
            }
            else
            {
                KeyboardSpacer.HeightRequest = 114;
            }
        }
    }
    
    protected async void Message_Unfocused(object sender, EventArgs args)
    {            
        if (Device.OS == TargetPlatform.iOS)
        {
            KeyboardSpacer.HeightRequest = 0;
        }
    }
    

提交回复
热议问题