【发布时间】:2016-09-20 09:34:45
【问题描述】:
我的问题在于接听电话或WiFi热点处于活动状态时,底部标签栏移到屏幕外。
这似乎是我需要使用的,但我没有成功 developer.xamarin.com/api/property/MonoTouch.UIKit.UIView.AutoresizingMask/
我该如何解决这个问题?
【问题讨论】:
标签: xamarin xamarin.ios uitabbar
我的问题在于接听电话或WiFi热点处于活动状态时,底部标签栏移到屏幕外。
这似乎是我需要使用的,但我没有成功 developer.xamarin.com/api/property/MonoTouch.UIKit.UIView.AutoresizingMask/
我该如何解决这个问题?
【问题讨论】:
标签: xamarin xamarin.ios uitabbar
这是一个布局问题。
我以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/
【讨论】: