Question

What I want to do is present a viewController that comes from the bottom and has a custom size. Whatever I seem to do either looks naff (e.g its animated up, flashes then goes transparent), is fullscreen or blacks out the whole screen. I have read a few solutions with custom delegates handing the animation but there must be a simple way. Also a lot of the solutions are for iOS 6 <

    HackViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"HackViewController"];
   vc.delegate = self;
   vc.modalPresentationStyle= UIModalPresentationCustom;
   vc.view.frame = CGRectMake(0, 0, 800, 400);
   vc.credits = CREDIT_PER_LEVEL * building.buildingLevels;
   vc.view.backgroundColor = [UIColor clearColor];

   [self presentViewController:vc animated:YES completion:^{
             vc.view.backgroundColor = [UIColor clearColor];
   }];
Was it helpful?

Solution

If you wanna add viewController (say VC2) as a modal over first viewController(say VC1), then in VC1, when you are presenting VC2,

[self presentViewController:VC2 animated:YES completion:nil];

In VC2 viewDidLoad

[self.view setBackgroundColor:[UIColor colorWithRed:211.0/255.0 green:211.0/255.0 blue:211.0/255.0 alpha:0.8]];

And, in AppDelegate under application didFinishLaunchingWithOptions:

[[self.window rootViewController] setModalPresentationStyle:UIModalPresentationCurrentContext];

You can create other views like imageView or label, etc in VC2

OTHER TIPS

If you only want to support iOS7 and above, you can implement this using a custom modal presentation style (UIModalPresentationCustom) and implement the transitioningDelegate to return a transitioning controller. In the transitioning controller, you will be called when the presentation is to happen, and you can provide the target frame of the presented view controller. This has a big advantage of using the system presentation model, and the system is aware a controller has been presented.

If you need to support iOS6, you need to add the presented view controller's as a subview, the view controller as a child view controller of the presenting view controller, and manager the view hierarchy yourself. This is less than optimal because of manual view hierarchy control and child/parent view controllers.

You don't have to presentViewController:, you can do that with addSubview: Keep doing what you are doing but add view of vc to view of presented view controller instead of presenting vc with presentViewController:

If you do that within an animation block, it would look nice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top