Question

I am trying to create a tabview project with three tabs (A,B,C). Tabs A and C are tableview controllers which work well. Tab B I want to make a ViewController that will use the camera using a AVCaptureSession. The question I have is how do I make Tab B display the camera modally over the tabview?

Was it helpful?

Solution

You could just present any modal controller without animation in viewDidLoad or viewWillAppear.

UIViewController *vc = [[UIViewController alloc] init];
vc.view.frame = [[UIScreen mainScreen] bounds];
vc.view.backgroundColor = [UIColor purpleColor];  // for testing
[self presentViewController:vc animated:NO completion:nil];

In that view controller you can do whatever you like, including starting a AVCaptureSession.

In order to return to the previously selected tab controller there are several options.

One is to switch to the desired tab when dismissing the modal view controller. Suppose it has a property or ivar called lastTab:

self.tabBarController.selectedViewController 
  = [self.tabBarController.viewControllers objectAtIndex:lastTab];

Another way is to never actually activate the tab with the modal view but launch the modal view controller directly from the other tabs. The other view controller could set the selected tab back to itself and then launch the modal view.

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