How to use presentModalViewController to create a transparent view

After iOS 3.2 there is a method to do this without any “tricks” – see the documentation for the modalPresentationStyle property. You have a rootViewController which will present the viewController. So here’s the code to success: viewController.view.backgroundColor = [UIColor clearColor]; rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext; [rootViewController presentModalViewController:viewController animated:YES]; With this method the viewController’s background will be transparent … Read more

How do I make a custom initializer for a UIViewController subclass in Swift?

class ViewController: UIViewController { var imageURL: NSURL? // this is a convenient way to create this view controller without a imageURL convenience init() { self.init(imageURL: nil) } init(imageURL: NSURL?) { self.imageURL = imageURL super.init(nibName: nil, bundle: nil) } // if this view controller is loaded from a storyboard, imageURL will be nil required init?(coder aDecoder: … Read more

Add a UIView above all, even the navigation bar

You can do that by adding your view directly to the keyWindow: UIView *myView = /* <- Your custom view */; UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow; [currentWindow addSubview:myView]; UPDATE — For Swift 4.1 and above let currentWindow: UIWindow? = UIApplication.shared.keyWindow currentWindow?.addSubview(myView) UPDATE for iOS13 and above keyWindow is deprecated. You should use the following: UIApplication.shared.windows.first(where: … Read more

iOS 9 Segue Causes App To Freeze (no crash or error thrown)

So basically the segue was freezing because of the UITextView‘s I was using in the destinationViewController. The following fixed the issue: Delete all UITextView‘s Add new UITextView’s you must leave the default lorem imposed text and change this programmatically in the viewDidLoad() This was the fix for me, and from the research I have done … Read more

How do I present a UIViewController from SKScene?

You’re creating a new view controller but never presenting it: SpriteViewController *viewController = [SpriteViewController alloc]; I’m assuming that SpriteViewController is what presents your SpriteMyScene, and you’d like to hand control back to the presenting SpriteViewController. You need to keep a reference to SpriteViewController in your SpriteMyScene subclass, and then access that reference when you call … Read more

Move UIView up when the keyboard appears in iOS

– (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } – (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } #pragma mark – keyboard movements – (void)keyboardWillShow:(NSNotification *)notification { CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; [UIView animateWithDuration:0.3 animations:^{ CGRect f … Read more

Access Container View Controller from Parent iOS

Yes, you can use the segue to get access the child view controller (and its view and subviews). Give the segue an identifier (such as alertview_embed), using the Attributes inspector in Storyboard. Then have the parent view controller (the one housing the container view) implement a method like this: – (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { … Read more