在iOS7以前若是須要隱藏StatusBar,比較簡單,直接在AppDelegate.cs中使用以下代碼就能夠進行隱藏:ide
UIApplication.SharedApplication.StatusBarHidden = true;
但這段代碼在iOS7中卻沒法實現StatusBar隱藏,而是將StatusBar透明顯示。通過在Xamarin網站查詢嚮導,具體方法是爲UIViewController增長一個重寫方法,學習
public override bool PrefersStatusBarHidden () { return true; }
這樣就能夠進行隱藏了,完成後效果以下圖所示:網站
在實際代碼編寫的時候爲了方便起見,能夠創建一個ViewController的類,繼承UIViewController類,增長StatusBarHidder的方法,之後再新增UIViewController的時候都繼承ViewController便可。具體代碼以下:this
using System; using System.Drawing; using MonoTouch.CoreFoundation; using MonoTouch.UIKit; using MonoTouch.Foundation; namespace Com.imStudio.iOSLibrarys { [Register("ViewController")] public class ViewController : UIViewController { public Boolean StatusBarHidder { get; set; } public ViewController() { } public override void DidReceiveMemoryWarning() { // Releases the view if it doesn't have a superview. base.DidReceiveMemoryWarning(); // Release any cached data, images, etc that aren't in use. } public override bool PrefersStatusBarHidden() { return this.StatusBarHidder; } public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view } } }
以上是個人解決辦法,歡迎和你們多多溝通學習,若有任何改進意見和建議,個人QQ是1243672,歡迎聯繫哦。spa