[英]Tab bar shows outside of screen
这是一个布局问题。
我将以iPhone5S的屏幕尺寸为例进行说明。
在正常情况下,您的视图尺寸为“ Frame = {X = 0,Y = 0,Width = 375,Height = 667}”,等于屏幕尺寸,但是iOS系统会将所有视图的框架设置为“ Frame = {X = 0,Y = 20,Width = 375,Height = 647}“激活个人热点。
并且还将调用所有视图的方法“ LayoutSubviews”,您可以按需捕获并处理它。
这是为您提供的示例,您应该根据自己找到一个解决方案。
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);
}
}
}
希望它能对您有所帮助。
如果您仍然需要建议,请在此处留言,我会稍后检查。
这可以使用约束代替自动调整蒙版大小来实现。 如果顶部栏的高度固定,底部视图的高度固定,中间视图的高度不固定,那么当状态栏展开时,中间视图将缩小而不是将所有内容向下推。 这是关于约束的教程
https://developer.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.