简体   繁体   中英

Tab bar shows outside of screen

My problem lies in when receiving a call or a WiFi hotspot is active, the bottom tab bar is shifted outside of the screen.

没有扩展状态栏 扩展状态栏

It seems like this is what I need to use, but I'm not succeeding with it developer.xamarin.com/api/property/MonoTouch.UIKit.UIView.AutoresizingMask/

How do I fix this issue?

It's a layout problem.

I will use iPhone5S's screen size as an example to explain it.

For normal situation, your view size is "Frame = {X=0,Y=0,Width=375,Height=667}", is equals to screen size, but iOS system will make all view's frame to "Frame = {X=0,Y=20,Width=375,Height=647}" when personal hotspot is activated.

And it will also call all view's method "LayoutSubviews", you can catch it and handle it as you wish.

This is a sample for you, you should can find a solution by yourself according it.

using System;
using CoreGraphics;
using UIKit;

namespace TestLayoutSubview
{
    public partial class ViewController : UIViewController
    {
        private MyView myView;

        protected ViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void LoadView()
        {
            myView = new MyView();
            this.View = myView;
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }

    class MyView : UIView
    {
        private UIView bottomBar;

        public MyView()
        {
            this.BackgroundColor = UIColor.Red;

            bottomBar = new UIView();
            bottomBar.BackgroundColor = UIColor.Green;
            this.AddSubview(bottomBar);

            nfloat barHeight = 50;
            bottomBar.Frame = new CGRect(0, UIScreen.MainScreen.Bounds.Height - barHeight, UIScreen.MainScreen.Bounds.Width,barHeight);
        }

        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            Console.WriteLine("Frame is changed.");
            Console.WriteLine("Frame = "+Frame);

            nfloat barHeight = 50;
            bottomBar.Frame = new CGRect(0, UIScreen.MainScreen.Bounds.Height - barHeight - Frame.Y, UIScreen.MainScreen.Bounds.Width, barHeight);
        }
    }
}

Hope it can help you.

If you still need some advice, leave the message here, I will check it latter.

This can be accomplished using contraints instead of auto resizing masks. If your top bar has a fixed height, your bottom view has a fixed height, and your middle view does not have a fixed height then when status bar expands your middle view will shrink instead of pushung everything down. Here's a tutorial on constraints

https://developer.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM