Hide MasterView - UISplitViewController with UITabController and UITableView - ios

I have a split view controller that contains a tab controller that contains a table view in each of its tab items - all on the "master side". The table view gives a list of items that the user can select from in order to control what is displayed on the "detail side".
I am trying to move the master table view off the screen after the user has made a selection - rather than the user needing to tap the screen to dismiss the master table view.
I am using the code below. As the code comments indicate it leaves an translucent "shadow" in place of the master side table view. What else do I need to be doing to completely move the master side table view off the screen.
- (void)hideSidebarNavPanel
{
/* This almost works - in that it moves the table view off the screen but leaves a "shadow" in its place.
This occurs whether we modify the frame for the tabBarView or the masterTableView or the masterView - or for all 3.
It seems that there is something else sitting below both of these that also needs to have its frame modified.
The question is what?
*/
UIView *masterView = self.view;
CGRect masterViewFrame = masterView.frame;
masterViewFrame.origin.x -= masterViewFrame.size.width;
NSArray *controllers = self.splitViewController.viewControllers;
UITabBarController *tabBarController = [controllers objectAtIndex:0];
UIView *tabBarView = tabBarController.view;
CGRect tabBarFrame = tabBarView.frame;
tabBarFrame.origin.x -= tabBarFrame.size.width;
// UIViewController *masterNavigationController = [tabBarController.viewControllers objectAtIndex:0];
// UIView *masterTableView = masterNavigationController.view;
// CGRect masterTableViewFrame = masterTableView.frame;
// masterTableViewFrame.origin.x -= masterTableViewFrame.size.width;
[UIView beginAnimations:#"showView" context:NULL];
masterView.frame = masterViewFrame;
tabBarView.frame = tabBarFrame;
//masterTableView.frame = masterTableViewFrame;
[UIView commitAnimations];
}

Related

UIViewController changes dimension after modal presentation

I have a UIViewController which is presented using a custom transition, and by design it only fills 90% of the screen's height.
This appears fine, and I've never had any issues with it. Let's call it View A. Now I am trying to present a full screen modal view on top of this, let's call that View B. This appearance works, but when View B is dismissed, View A reappears, but has been expanded to fill the entire bounds of the screen.
Here's the presentation code I'm using:
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
...
// Presentation
const CGFloat viewHeight = (screenBounds.size.height * 0.9);
const CGRect beginFrame = CGRectMake(0, screenBounds.size.height, screenBounds.size.width, viewHeight);
const CGRect finalFrame = CGRectMake(0, (screenBounds.size.height - viewHeight), screenBounds.size.width, viewHeight);
// Dim
self.dimmedView.alpha = 0.0;
[transitionContext.containerView addSubview:self.dimmedView];
[transitionContext.containerView addConstraints:[NSLayoutConstraint allConstraintsFromViewToSuperview:self.dimmedView inset:UIOffsetZero]];
// Prepare
UIView * const toView = toVC.view;
toView.frame = beginFrame;
[transitionContext.containerView addSubview:toView];
// Animate
[UIView animateWithDuration:kAnimationDuration delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:0.25 options:0 animations:^{
toView.frame = finalFrame;
self.dimmedView.alpha = 0.6;
self.tabBarController.view.layer.cornerRadius = 8.0;
self.tabBarController.view.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:^(BOOL finished) {
[transitionContext completeTransition:!transitionContext.transitionWasCancelled];
[offshootView removeFromSuperview];
}];
...
}
Has anyone seen this before, and know how to stop the system from resizing View A?
I think the problem is that you modify the size of the view controller's root view, although it is handled by the view controller. The documentation for UIViewController says:
A view controller’s root view is always sized to fit its assigned
space.
Why not add another (fully transparent) view as a child to the root view, where you place all your content? Doing so let's you keep the root view at 100% while changing the new view's size to 90% when you want to. If I understand you correctly this will accomplish the same thing without touching the root view.
For this to work you should set the view controllers Presentation property in the Storyboard attribute inspector to Over Full Screen. If you want to set it by code you set the view controller's .modalPresentationStyle = UIModalPresentationOverFullScreen. By setting this the underlying view controller will stay on screen after you have presented your view controller and continue to be visible where you have transparency in your view.
Documentation for UIViewController
Documentation for UIModalPresentationOverFullScreen

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
}
}

Tableview frame issue when put in a scrollview

I wanted to post a gif but apparently I don't have enough reputation. Oh well, whatever; I was using UIPageViewController, but for some reason I decided to go with a more manual solution by using UIScrollView and adding the views of UITableViewControlllers to the corresponding offsets (pages). I have 4 UItableViewControllers on each page (the views of table view controllers) and all of these are added to the container view controller (which has the UIScrollView) as child view controllers.
The actual problem is when I made the switch, table views began refusing to go all the way down and part of the final table view cell stays trimmed by the end of the screen when the scrolling ends.
So, wanted to ask if anyone came across something like this before of know how to get rid of this. I know I could always use a library, but I want to learn. Here is some code:
_containerScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
_containerScrollView.contentSize = CGSizeMake(_containerScrollView.frame.size.width * 4, 0.0f);
_containerScrollView.pagingEnabled = YES;
[self.view addSubview:_containerScrollView];
UITableViewController *vc1 = [[UIViewController alloc] init];
UITableViewController *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:#"trendingViewController"];
UITableViewController *vc3 = [self.storyboard instantiateViewControllerWithIdentifier:#"placesViewController"];
UITableViewController *vc4 = [self.storyboard instantiateViewControllerWithIdentifier:#"favoritesViewController"];
self.rallyViewControllers = [NSArray vc1, vc2, vc3, vc4, nil];
[self addViewControllers];
Other methods;
- (void)addViewControllers{
if (self.rallyViewControllers == nil) {
return;
}
for (int i = 0; i < [self.rallyViewControllers count]; i++) {
UIViewController* viewController = [self.rallyViewControllers objectAtIndex:i];
[self addChildViewController:viewController];
[viewController didMoveToParentViewController:self];
[_containerScrollView addSubview:viewController.view];
}
}
This is called in viewDidLayoutSubviews
- (void)configureFrames{
if (self.rallyViewControllers == nil) {
return;
}
CGFloat width = _containerScrollView.frame.size.width;
CGFloat height = _containerScrollView.frame.size.height;
for (int i = 0; i < [self.rallyViewControllers count]; i++) {
UIViewController *viewController = [self.rallyViewControllers objectAtIndex:i];
viewController.view.frame = CGRectMake(i * width, 0.0f, width, height);
}
}
I should state upfront that I didnt completely understand your description of
"table views began refusing to go all the way down and part of the
final table view cell stays trimmed by the end of the screen when the
scrolling ends."
My answer is based on an issue I faced before. My setup is a uitableview in the storyboard container view ( without any parent scrollview)
I faced this issue where part of the tableview was cut off and I could not see about 5 bottom rows.
Turns out I did not have any constraints setup between the parent container view and the tableview.
To determine if your tableviews are rendering fine, get your project running in XCode and then press on the below button
This button will then pause your app and give you a visual stack of the the different views that are currently rendered in your app. You can then see if any of the children ( in your case tableviews) are rendered outside the frame of the parent view in which case that portion will not be visible. This indicates that you either dont have constraints (or) the current constraints you have are incorrect.
I got it. The problem was when I added the view controllers views to the scroll view, they returned dimensions as if there was no navigation bar. But they were still positioned under the navigation bar, which caused total view to have 64 pt more height than the screen could show. when I manually subtracted 64 pt from views, and it was fixed. But since that is a very crude way of doing this, I then tried to fix it by fiddling with auto-layout, which ended up fine.

Is it correct to move the navigation bar frame?

I have a navigation bar based ipad app.
At some point I want to push another view controller into the views controller hierarchy. Then, when the users tabs some button I want to show a leftMenu controller. To do so I have two views:
A content view which has all the content
And a not visible view which is the leftMenu. This one is under the content view.
So when the user presses the button, what Im doing right now is moving the content view and the navigation bar to the right to make the leftMenu visible:
self.navigationController.navigationBar.frame = CGRectMake(271.0, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, self.self.navigationController.navigationBar.frame.size.height);
self.contentView.frame = CGRectMake(271.0, self.contentView.frame.origin.y, self.contentView.frame.size.width, self.contentView.frame.size.height);
This is working, but the first row in the left menu is not "clickable" where the nav bar is supossed to be. Its like the navigation bar is still there capturing the tab events.
Is it correct to do?:
self.navigationController.navigationBar.frame = CGRectMake(271.0, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width, self.self.navigationController.navigationBar.frame.size.height);
If not, whats the propper way to achieve what I want?
Heres and image ilustrating what the problem is:
I think it's best to use a custom container controller to do this kind of thing, rather than moving a navigation bar. In IB, this can be set up quite easily. Start with a UIViewController, add a container view to it, and size how you want. Then in the inspector, set its x value to minus its width, which will put it off screen to the left. Then add another container view and size it to be full screen. You can then delete the view controller that you got with that container view, and right drag from the container view to your initial navigation controller (of your already setup UI) to connect it up with an embed segue. The UIViewController that you started with should be made the initial view controller of the storyboard. To move in the side view, I use this code in that custom container controller:
-(void)slideInLeft {
if (isRevealed == NO) {
[UIView animateWithDuration:.6 animations:^{
leftView.center = CGPointMake(leftView.center.x + 100, leftView.center.y);
mainView.center = CGPointMake(mainView.center.x + 100, mainView.center.y);
} completion:^(BOOL finished) {
isRevealed = YES; ;
}];
}else{
[UIView animateWithDuration:.6 animations:^{
leftView.center = CGPointMake(leftView.center.x - 100, leftView.center.y);
mainView.center = CGPointMake(mainView.center.x - 100, mainView.center.y);
} completion:^(BOOL finished) {
isRevealed = NO;
}];
}
}
leftView and mainView are IBOutlets to the 2 container views. I call this method from a button in the main view controller (the root view controller of the navigation controller that's embedded in the large container view):
-(IBAction)callSlideIn:(id)sender {
[(ViewController *)self.navigationController.parentViewController slideInLeft];
}
I found a "fast" way to achieve this (and a bit hacky imo)
I added the leftMenu view to the top view in the views hierachy:
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:self.leftMenu.view];
Now it is les deep than the navigation bar and, of course, its clickable

iPad UIModalPresentationFormSheet with UITabBarController's moreNavigationController edit mode issue

This is seemingly a bug, but i'm wondering if anyone can think of a workaround.
On iPad, you present a view controller as a UIModalPresentationFormSheet. This view controller is extending UITabBarController and has enough controllers to automatically display the "more" tab bar button. Once you tap on the more button it will display the list correctly, but as soon as you tap on 'edit' it presents the edit view larger then the actual form sheet (cropped inside the form sheet), causing the content to be out of view, including the toolbar with the "done" button. The only way to dismiss is to force quit the app.
To verify that it's not something specific to my app I started a single view project, and presented a simple modal view. This modal view controller extends UITabBarController and has the following init method:
- (id)init {
self = [super init];
if (self) {
self.modalPresentationStyle = UIModalPresentationFormSheet;
NSMutableArray *controllers = [NSMutableArray array];
for (int i = 0; i< 15; i++) {
UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
vc.title = [NSString stringWithFormat:#"view %i", i];
[controllers addObject:nav];
}
self.viewControllers = controllers;
}
return self;
}
I also tried adding the modalPresentationStyle to moreNavigationController with no change.
Good day, dizy.
A nice challenge you've made. Here is a solution, maybe it's a bit hardcore, but it works.
I've done as you wrote – subclassed UITabBarController and presented it as a modal view controller. And run into the same problem. When tapping "edit" button in "More" screen UITabBarCustomizeView appears and it's frame is inadequate.
So I've done the following. I've made MyModalTabBarVC a delegate of itself and implemented tabBarController:willBeginCustomizingViewControllers: method:
- (void)tabBarController:(UITabBarController *)tabBarController
willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
UIView *modalView = self.view;
CGRect bounds = modalView.bounds;
UIView *customizationView = [[modalView subviews] objectAtIndex:1];
UIView *customizationNavBar = [[customizationView subviews] objectAtIndex:0];
CGRect navBarFrame = [customizationNavBar frame];
navBarFrame.size.width = bounds.size.width;
customizationNavBar.frame = navBarFrame;
customizationView.frame = bounds;
}
So when this method is called UITabBarCustomizeView is already created. And a wrong frame can be changed manually. If you log po [self.view subviews] at the start you'll get:
(id) $1 = 0x06c6a940 <__NSArrayM 0x6c6a940>(
<UITransitionView: 0xd744ab0; frame = (0 0; 540 571); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xd744b50>>,
<UITabBarCustomizeView: 0x6c5e570; frame = (0 -384; 768 1004); animations = { position=<CABasicAnimation: 0x6c569a0>; }; layer = <CALayer: 0x6c618d0>>,
<UITabBar: 0xd744110; frame = (0 571; 540 49); autoresize = W+TM; layer = <CALayer: 0xd742b80>>,
)
PS. This solution doesn't fix animation. As you can see from log, corrupted animation is already created and charged. I hope that canceling it and adding a new one, appropriate, will not be a problem.
The modal view's viewController must be causing the glitch.
You could try to:
hide the tab bar while editing and un-hiding it when the done button
is pressed.
create a custom toolbar for the view controller, this could be done
with a UIView, so that it's set always be on top of the view.
resize your individual tabs. Best way to do this is to create your
own custom tab bar with a UIViewController and IBActions connected
to UIButtons with IBOutlets.
Why would you have so many tabs in the modalPresentationStyle? I personally would use push segue instead.
Try pushing to a new set of view controllers that are under their own navigation controller as well. There would be more room for the tab bar. To get back, put a back button in the toolbar that pops the push, or pushes back to the original.

Resources