Programmatically change rootViewController of storyBoard

Objective-C: UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@”MainStoryboard” bundle:nil]; UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@”tabBarcontroller”]; [[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController]; Swift : let mainStoryboard: UIStoryboard = UIStoryboard(name: “Main”, bundle: nil) let viewController = mainStoryboard.instantiateViewControllerWithIdentifier(“tabBarcontroller”) as UITabBarController UIApplication.sharedApplication().keyWindow?.rootViewController = viewController; Swift 3: let mainStoryboard: UIStoryboard = UIStoryboard(name: “Main”, bundle: nil) let viewController = mainStoryboard.instantiateViewController(withIdentifier: “tabBarcontroller”) as! UITabBarController UIApplication.shared.keyWindow?.rootViewController = viewController Swift … Read more

Checking if a UIViewController is about to get Popped from a navigation stack?

Override the viewWillDisappear method in the presented VC, then check the isMovingFromParentViewController flag within the override and do specific logic. In my case I’m hiding the navigation controllers toolbar. Still requires that your presented VC understand that it was pushed though so not perfect.

How to allow only single UIViewController to rotate in both Landscape and Portrait direction?

Simple but it work very fine. IOS 7.1 and 8 AppDelegate.h @property () BOOL restrictRotation; AppDelegate.m -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(self.restrictRotation) return UIInterfaceOrientationMaskPortrait; else return UIInterfaceOrientationMaskAll; } ViewController -(void) restrictRotation:(BOOL) restriction { AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; appDelegate.restrictRotation = restriction; } viewDidLoad [self restrictRotation:YES]; or NO

CAGradientLayer, not resizing nicely, tearing on rotation

When you create a layer (like your gradient layer), there’s no view managing the layer (even when you add it as a sublayer of some view’s layer). A standalone layer like this doesn’t participate in the UIView animation system. So when you update the frame of the gradient layer, the layer animates the change with … Read more