2016-09-20 125 views
0

我的問題在於,當接到電話或WiFi熱點處於活動狀態時,底部的標籤欄會移出屏幕。標籤欄顯示在屏幕外

No extended status bar Extended status bar

好像這就是我需要使用,但我不會用它 developer.xamarin.com/api/property/MonoTouch.UIKit.UIView.AutoresizingMask/

成功

如何解決此問題?

回答

1

這是一個佈局問題。

我將以iPhone5S的屏幕尺寸爲例來解釋它。

對於正常情況,您的視圖大小爲「Frame = {X = 0,Y = 0,Width = 375,Height = 667}」,等於屏幕大小,但iOS系統會將所有視圖的框架設置爲「當個人熱點被激活時,幀= {X = 0,Y = 20,寬度= 375,高度= 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); 
     } 
    } 
} 

希望它能幫助你。

如果你仍然需要一些建議,留言在這裏,我會檢查後者。