Skip to content

Instantly share code, notes, and snippets.

@patridge
Created February 5, 2015 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patridge/d08bcb4923e14c432305 to your computer and use it in GitHub Desktop.
Save patridge/d08bcb4923e14c432305 to your computer and use it in GitHub Desktop.
Sample: BTProgressHUD blocking tab bar
using System;
using Foundation;
using UIKit;
using CoreGraphics;
using BigTed;
using System.Threading.Tasks;
using System.Linq;
using ObjCRuntime;
namespace HudOverTabsSample {
public class NumberedTabViewController : UIViewController {
readonly int tabNumber;
public NumberedTabViewController(int tabNumber) {
this.tabNumber = tabNumber;
}
UITextView someView;
bool hasAdjustedForTopLayoutGuide = false;
public override void ViewDidLayoutSubviews() {
base.ViewDidLayoutSubviews();
if (!hasAdjustedForTopLayoutGuide && UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) {
View.Subviews.ToList().ForEach(v => v.Center = new CGPoint(v.Center.X, v.Center.Y + TopLayoutGuide.Length));
}
hasAdjustedForTopLayoutGuide = true;
}
public override void ViewDidLoad() {
base.ViewDidLoad();
View.BackgroundColor = UIColor.White;
someView = new UITextView() {
BackgroundColor = UIColor.LightGray,
Text = string.Format("Tab {0} Content", tabNumber),
};
someView.Frame = new CGRect(new CGPoint(6f, 6f), new CGSize(View.Bounds.Width - 12f, 50f));
View.Add(someView);
}
public override void ViewDidAppear(bool animated) {
base.ViewDidAppear(animated);
var hud = ShowHud("Oh hai");
Task.Delay(3000).ContinueWith((task) => {
InvokeOnMainThread(() => {
hud.Dismiss();
});
});
}
ProgressHUD ShowHud(string text) {
// Need discrete HUDs so one tab won't try to hide anothers pending HUD.
var hud = new ProgressHUD();
hud.Show(status: "Oh hai", maskType: ProgressHUD.MaskType.Gradient);
return hud;
}
}
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate {
public override UIWindow Window { get; set; }
UITabBarController rootController;
public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
var tabImage = UIImage.FromBundle("star");
rootController = new UITabBarController() {
ViewControllers = Enumerable.Range(0, 4).Select(i => {
var tabBarItem = new UITabBarItem(i.ToString(), tabImage, tabImage);
return new NumberedTabViewController(i) { TabBarItem = tabBarItem };
}).ToArray(),
};
Window = new UIWindow(UIScreen.MainScreen.Bounds);
Window.RootViewController = rootController;
Window.MakeKeyAndVisible();
return true;
}
}
public class Application {
static void Main(string[] args) {
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
try {
UIApplication.Main(args, null, "AppDelegate");
}
catch (Exception ex) {
HandleException(ex);
}
}
static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) {
HandleException(e.ExceptionObject as Exception);
}
static void HandleException(Exception exception) {
Console.WriteLine("Top-level exception: {0}", exception);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment