简体   繁体   English

标签栏显示在屏幕外部

[英]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. 我的问题在于,当接听电话或WiFi热点处于活动状态时,底部的标签栏移到屏幕外部。

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

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/ 似乎这是我需要使用的东西,但我没有成功使用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. 我将以iPhone5S的屏幕尺寸为例进行说明。

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. 在正常情况下,您的视图尺寸为“ Frame = {X = 0,Y = 0,Width = 375,Height = 667}”,等于屏幕尺寸,但是iOS系统会将所有视图的框架设置为“ Frame = {X = 0,Y = 20,Width = 375,Height = 647}“激活个人热点。

And it will also call all view's method "LayoutSubviews", you can catch it and handle it as you wish. 并且还将调用所有视图的方法“ LayoutSubviews”,您可以按需捕获并处理它。

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/ https://developer.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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