dismissViewControllerAnimated leaves black screen - ios

I've read a number of threads on stackoverflow about this issue, but none seemed to have a fix that worked for my most basic and straightforward case.
I'm using XCode 7.2.1 and iOS 9.2
I have a class (code shown below) that accepts a UIViewController to use as the presenter of a UINavigationController.
This code below is from ONE class, and it does both the presenting and dismissing.
Starting with screen 1 pictured below, the user taps a button in the upper left corner, which then presents the UINavigationController in screen 2. Finally, tapping the "Done" button in the upper right corner of the UINavigationController (screen 2) causes a black screen... screen 3.
Lastly, you'll notice on the black screen a little red circle with a number in it.
That is from the tab bar in screen 1 at the bottom. For some reason it stacked up all the tab bar buttons in the corner, and left a little area for them to peek out.
-(id)initWithDashboardParentViewController:(TabMapController*)mapVC propertyDelegate:(id<iRpPropertyDelegate>)propertyDelegate
{
self = [super init];
if (self)
{
mapViewController = mapVC;
thePropertyDelegate = propertyDelegate;
}
return self;
}
-(void)displaySpreadsheetOfAllSubitems
{
UIViewController *theContentController;
// Create a generic gridview view controller and initialize it with the data that will be shown.
theContentController = [[iRpGenericGridViewController alloc] initWithPropertyDelegate:propertyDelegate dashboardDataItem:spreadsheetTableData];
theContentController.edgesForExtendedLayout = UIRectEdgeNone;
// Create a navigation controller and embed the content view controller.
UINavigationController *theNavController = [[UINavigationController alloc] initWithRootViewController:theContentController];
// If a detail item was found for this section, then display it in the navigation controller.
if (theNavController)
{
// Set up the 'Done' navigation bar button.
theNavController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(detailDisclosureDone)];
[mapViewController presentViewController:theNavController animated:YES completion:^(void){}];
}
}
-(void)detailDisclosureDone
{
[mapViewController dismissViewControllerAnimated:NO completion:^{}];
}

Well, I did figure out that it has something to do with AutoLayout and the constraints set on my root view controller.
I made a constraint that the root view controller has to be at least a given height, instead of just saying it was 0-nearestSuperview, etc, and now I'm seeing a portion of my view.

Related

Unable to click "under" a hidden TabBar

I hide my tab bar like so:
self.tabBarController.tabBar.hidden = YES;
And because now there is a black bar where it once stood I stretch the view which is a UIWebView on top(or is it under?) that empty space. The UIWebView is in a UIViewController. I do that with a constraint which by default is like so:
The code for the constraint:
if(self.tabBarController.tabBar.hidden){
self.webviewBottomConstrain.constant = -self.tabBarController.tabBar.frame.size.height;
}else{
self.webviewBottomConstrain.constant = 0;
}
However if I tap the device on the place where the TabBar was it will not execute. It is as if there is something invisible there with the size of the tab bar. I have also tried hiding it the way this thread sugests. Still the same result.
Update: It seems that when you tap on the invisible tab bar the tap is recognized by the tab bar and not by the view that is visible under the tab bar
self.extendedLayoutIncludesOpaqueBars = YES;
this will solve you problem
You hide your tabBar by setting its hidden property to NO? Try setting it to YES. Unless I am misunderstanding what you are trying to do, it seems like your tab bar is not hidden with that code.
Another thing I would check is to see if User Interaction Enabled is checked for the web view. If it is not, that can seem like there is something invisible blocking you from interacting with your view.
Well I am using quite ugly hack to fix this. I am hiding the tab bar in another way now:
if (shouldShow) {
self.hidesBottomBarWhenPushed = NO;
UIViewController *someView = [[UIViewController alloc] init];
[self.navigationController pushViewController:someView animated:NO];
[self.navigationController popToViewController:self animated:NO];
} else if (shouldHide) {
self.hidesBottomBarWhenPushed = YES;
self.tabBarController.hidesBottomBarWhenPushed = YES;
self.navigationController.hidesBottomBarWhenPushed = YES;
UIViewController *someView = [[UIViewController alloc] init];
[self.navigationController pushViewController:someView animated:NO];
[self.navigationController popToViewController:self animated:NO];
}
I do need that random view because I cannot push the view on itself.
I had the same issue when hiding the tab bar by moving it offscreen to the bottom. My custom UITabBarViewController was intercepting the touch events in the area vacated by the tab bar, so instead of changing the frame of the tab bar to move the tab bar offscreen, I extended the height of my tab bar view controller so that the tab bar still moved offscreen, but the child view above the tab bar now filled that space. This allowed the touches to be received by the child view.
As you may see with view hierarchy instrument, UITabBar is not directly blocking your tap, but your current view controller's view height is not full screen:
So, the tap doesn't response because your finger's y position is higher than view's maxY.
Code like this (inside your UITabBarController) will expand your view's height, according to tabbar visibility, and all tap events will work correctly.
func updateTabBarAppearanceWithDegree(_ degree: CGFloat) {
let screenHeight = UIScreen.main.bounds.size.height
let tabBarHeight = self.tabBar.frame.size.height
self.tabBar.frame.origin.y = screenHeight - tabBarHeight * degree
self.tabBar.alpha = degree
let currentNavigation = self.selectedViewController as? UINavigationController
if let currentTopView = currentNavigation?.viewControllers.last?.view {
currentTopView.frame.size.height = self.tabBar.frame.origin.y
}
}

UITabBar is removed when pushed back on UITableViewController but not ViewController

I have an iPhone app, which has a UITabBar with 5 tabs in it, each of the 5 tabs have NavigationViewcontroller which push to other "sub" views as the user selects different options.
2 of the tabs are UItableViews and 3 are UIviews.
When I push from a UITableView to another uiview, then return to the original UITableView, the tab bar appears white instead of a is original bar with 5 tbs on it.
However if I do the same thing from one of the 3 UIView (which is are the tab bar) to another UIView, then return the tab bar is as fine.
I am using storyboards (for the second time) and I have checked the Atributes inspector in the navigation controller and the root views for the UIView that are working and the table UITableView that are not and I cannot see any difference.
My question is should they be the same?
I also use this code to try and stop the bar from being hidden in the init method of the first view and the tab view,
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed=NO;
}
return self;
Any help or pointers would be greatly appreciated as my reading has left me blank
Use the following way to hide the bottom bar. When pushed it hides the bottom bar and on popping it reveals back the bottom bar
- (void)pushNewViewController{
MyNewViewController *viewController = [self instantiateNewViewController];
viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController: viewController animated:YES];
}

White space in place of a hidden tab bar

I use UINavigationController inside UITabBarController and one of the screens in my navigationcontroller is a UIImageView. When I want to show that image full screen I have to hide the navigation bar and tab bar. I'm able to hide the navigation bar correctly but when I hide the tab bar, it leaves 50px of white space. Any suggestion?
Thank you for all
I have found the best solution to my problem .
MyImageViewController.hidesBottomBarWhenPushed = YES ;
[self.navigationController pushViewController:MyImageViewController animated:YES];
It gave me the response I wanted .
Thank you for your share
I think you can show it on model view controller.
Put modelviewcontroller over tabbarcontroller.
FullImageView*objFullImageView = [[FullImageView alloc] initWithNibName:#"FullImageView" bundle:nil];
objFullImageView.image = OriginalImage;
UINavigationController *tempNav = [[[UINavigationController alloc] initWithRootViewController:objFullImageView] autorelease];
[objFullImageView release];
self.tabBarCtrl.modalPresentationStyle = UIModalPresentationPageSheet;
[self.tabBarCtrl presentModalViewController:tempNav animated:YES];
FullImageView.h
{
UIImage *image;
}
#property(nonatomic, retain) UIImage *image;
FullImageView.m
#synthesize image;
viewDidLoad /ViewWillApper
{
//Set image in your UIImageView
}
I solved this problem by changing constraints.
I had a view in my tabbar viewController whose bottom constraint was given (=0) from Safe Area.bootom. This was causing white space at the bottom. Changing this constraint to (=0) from Superview.bottom solved my proble.
You can increase the height of your image view frame.
After hours of research, this thread resolved my blank space issue when hidding the tabbar: hiding TabBar when rotating iPhone device to landscape
It's been quite a long time since the original post, but I thought I could jump in and add my thoughts.
Another option would be to set the option Hide bottom bar on push directly within the Storyboard for all those controllers which are pushed within a navigation controller inside a tabbar controller. This works within iOS7 simulator/targets as well, both at 3.5" and 4".

UINavigationController has extra status bar gap at top

This looked simple enough when I set it up, but I can't explain why this gap is present between the status bar and the navigation bar. Also, the contained view looks like it may be properly aligned, and it's just the nav bar that is shifted down. The gap looks like the size of the status bar, so I expect that has something to do with it, but I don't know what.
Here is the code for setting up the navigation controller:
- (void)viewDidLoad
{
[super viewDidLoad];
advancedVC = [[AdvancedSearchFormVC alloc] initWithNibName:#"AdvancedSearchForm" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:advancedVC];
nav.navigationBar.tintColor = [UIColor defaultNavBarTint];
nav.navigationBar.topItem.title = NSLocalizedString(#"SearchTitle", nil);
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"SearchButton", nil) style:UIBarButtonItemStylePlain target:self action:#selector(refreshPropertyList:)];
nav.navigationBar.topItem.rightBarButtonItem = searchButton;
self.view = nav.view;
}
The rootViewController uses a view from a xib file, where I have simulated the status bar, the navigation bar, and the tab bar.
The problem is indeed that the navigation controller always expects to leave room for the status bar, which is the 20 pixel gap. I searched around for a while before I found this solution which works:
//nav is assumed to be a subclass or instance of UINavigationController
nav.view.frame = CGRectOffset(nav.view.frame, 0.0, -20.0);
//you can then add the navigation's view as a subview to something else
I originally found an answer which did this offset to the navigationbar's view, but it didn't work. It works when you do it to the navigation controllers actual view.
I use this technique to add a navigation controller from another nib to an empty view of my main nib, so I can position it anywhere within the main screen as a subview. By using an empty view as a placeholder and positioning frame on my main nib, I create a separate nib and class to manage the navigation, which manages other nibs used to handle their screens. This way I can solve the classic "how do I add a banner, image, or custom views above my navigation controller" while having a navigation controller as a subview...in iOS 5 to be specific.
It's also worth mentioning that I use the app delegate to store and access all the other controllers, so they are retained by a persistant instance which I can access from any class. Create and synthesise some properties in the app delegate of all your controllers, and in viewDidLoad create instances. That way I can reference all the controllers used in my app later anywhere by adding:
//this shows how to store your navigation controllers in the app delegate
//assumes you've added 2 properties (UINavigationController*)"navController" and (UIViewController*)"rootController" in your app delegate
//...don't forget to add #import "AppDelegate.h" to the top of the file
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[app.navController pushViewController: app.rootController animated:YES];
//now apply the offset trick to remove the status gap
app.navController.view.frame = CGRectOffset(app.navController.view.frame, 0.0, -20.0);
I had the same problem before. The code I used to add UINavigationBar to UIViewController:
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:self];
[self.view addSubview:nc.view];
Solution:
Check the box "Wants Full Screen" with Attributes inspector of your UIViewController.
You can try to set the attribute Under Top Bars unchecked from Attributes section of UIViewController.
As we all know by now, the 20 pixel shift is to provide space for the Status bar on the top.
But infact, the view controllers coordinate system is kept in place and only the navigation bar frame is shifted down by 20 pixels. This makes the navigation bar to actually overlap the top 20 pixels of the view.
Logging the navigation bars frame origin, it will show (0.0, 20.0)
So the solution is to simply reposition the navigation bar's origin to (0.0, 0.0) in ViewWillAppear.
self.navigationController.navigationBar.frame = CGRectMake(0.0, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
Since you're adding advancedVC as a subview of self.view, it is being added inside the frame of self.view which I'm guessing is already compensating for the status bar.
You can probably easily fix this by adding this line:
nav.view.frame = self.view.frame;
Just above this line:
self.view = nav.view;
-
Other Thoughts
I'm not privy to your entire setup, but self.view may not be needed at all. Simply make your advancedVC instance the rootViewController of the UIWindow instance contained in your App Delegate.
The problem was resolved by fixing the way the navigation controller was inserted. Instead of inserting it into a view that had been put onto the tabbar controller, the navigaiton controller should have been put directly onto the navigation controller.
advancedSearchFormVC = [[AdvancedSearchFormVC alloc] initWithNibName:#"AdvancedSearchForm" bundle:nil];
UINavigationController *searchNavController = [[UINavigationController alloc] initWithRootViewController:advancedSearchFormVC];
This is just one controller that is on the tabbar controller, replacing the advancedSearchFormVC at the same time. Then this nav controller was added to the array of controllers that got put onto the tabbar controller.
Sorry for any trouble, but this was one of those problems I can look directly at and not see it. I should have seen this earlier, because I had another nav controller already on the tabbar controller, and it was set up the same way.
Thanks for your assistance.
The problem is that UINavigationController.view should be added to the top view.
Just find the top one and it will be working great.

creating button for popover view anchor at run time

This may not be possible, but I'm hoping someone will have an idea how to do it.
I have an app I'm porting from iPhone only to Universal. On the iPhone, I'm using a Tabbed application. I use three tabs for the normal data to be displayed. I have a forth tab that's only displayed if certain conditions are met. To add the tab, I do:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
UITabBarController *tabController = (UITabBarController *) self.rootViewController;
NSMutableArray* newArray = [NSMutableArray arrayWithArray: tabController.viewControllers];
[newArray addObject: [theStoryboard instantiateViewControllerWithIdentifier: #"AdditionalView-Phone"]];
[tabController setViewControllers:newArray animated:YES];
}
For the iPad, I have enough space on the initial view to display everything from the main three tabs in the iPhone UI. So all I need is one additional (small) view for the "Additional" data. I wanted to do it using a popOver view, so I set up the initial view with a Nav bar and popover button as in the Utility App template. But now I'm stuck. I can't figure out how to create that popover button at run time and make it do the segue to the popOver view properly. I can add the button like this:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] initWithTitle: #"Modem" style: UIBarButtonItemStylePlain target: self action: #selector(togglePopover:)];
self.navBar.topItem.rightBarButtonItem = flipButton;
but I get an exception: 'NSInternalInconsistencyException', reason: 'UIStoryboardPopoverSegue must be presented from a bar button item or a view.' I'm pretty sure this is because I don't have an anchor set for the popOver segue. The button doesn't exist in the storyboard, so I can't set it there. And I can't seem to find an API to set it at run time.
I also tried creating the button in IB, but not in the view hierarchy, and then just setting the rightBarButtonItem property to my existing button. That also works, but I still can't set that button as the anchor for the popover view. I can set the Navigation Bar as the anchor, but that makes it anchor to the title in the nav bar, which looks silly.
Any ideas?
I had the same problem and solved it by creating a UIBarButtonItem in the Storyboard for the view controller but not part of the view hierarchy.
In IB, Drag a bar button item to the dark bar below the view controller view, drop it next to the "First Responder" and "View Controller" icons. Create a (strong) IBOutlet for it. Then create a popover segue from it to the destination view controller by dragging from the bar button item to the destination. It seems like this is the only way to set it as the anchor. Choosing it as the anchor for an existing segue does not work (looks like an IB bug).
In viewDidLoad you can assign this bar button item to the navigationItem (or where ever you like) and the segue works as expected.
I was curious about this too so I made a quick test project. You're right, there doesn't seem to be a way to configure the popover segue at runtime or add an anchor point to a button that's not in the view hierarchy using Interface Builder.
My solution was to set everything up in IB with the UIBarButtonItem visible and connected to an IBOutlet property, then remove it from the navigation bar in -viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = nil;
}
Then I simply add it back or remove it by tapping another button:
- (IBAction)toggleBarButtonItem:(id)sender
{
UIBarButtonItem *item = (self.navigationItem.rightBarButtonItem == nil) ? self.popoverBarButtonItem : nil;
[self.navigationItem setRightBarButtonItem:item animated:YES];
}
You could conditionally keep or remove the button in -viewDidLoad the same way. The segue remains anchored to the UIBarButtonItem.
I'm gonna try making a dummy view that's the size and shape of the views I want to present the popover from, wire that to the segue popover target, and then move the view to the right position in prepareForSegue:sender:
I'm not sure this is exactly what you want, but this is what I would do. Create a button and set it up with some target/action. Call that target/action method
presentPopover:(UIButton *)sender;
Then in the presentPopover method, say
UIViewController *customAdditionalViewController = [[MySpecialVC alloc] init];
//Configure the customAdditionalViewController
//Present the customAdditionalViewController in a Popover
UIPopoverController *popover = [[UIPopoverController alloc] initWithViewController:customAdditionalViewController];
//Set popover configurations
[popover presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:/*whatever you want*/ animated:YES];
That is how I would handle your use case.

Resources