UISplitViewController - Resizing Detail View - ios

I am using a UISplitViewController in my iPad app and I dont really like the way the popover view slides in and covers a third of the screen and stays there when in Portrait mode.
I am resizing the Detail view when the popover is slid into view and this works fine except the navigation bar at the top stay the full width (And goes underneath the popover).
I basically want it to look like it does when in Landscape mode.
This is the code I use to resize the view:
UIViewController *masterView = [svc.viewControllers objectAtIndex:0];
UINavigationController *detailNavView = [svc.viewControllers objectAtIndex:1];
UIViewController *detailView = [detailNavView.viewControllers objectAtIndex:0];
detailView.view.frame = CGRectMake(masterView.view.frame.size.width, 0, detailView.view.frame.size.width - masterView.view.frame.size.width, detailView.view.frame.size.height);
I have tried settingdetailNavView.view.frame but nothing happens.
How can I resize the overall detail view including nav bar?

Hmm, I think the UISplitViewController is not really that flexible. It's just something that Apple decided: split in landscape, popover in portrait. The detail view is occupying the whole view (i.e. the main view) of this controller, so you would have to define it as a subview of the main view of another kind of controller to manipulate its navigation bar like this.
The only solution to customize the portrait views is to actually do away with Apple's version of the split view controller and roll your own.
Perhaps the most pragmatic solution is just to dismiss the popover after an item is selected and displayed in the detail view.

The answer is UISplitViewController's preferredPrimaryColumnWidthFraction property - set it from 0.0-1.0 to specify relative spacing master view takes up.

Related

UINavigationBar has wrong height on rotation in Action Extension

I wrote a little app that includes an action extension.
Now I am struggling with a rotation issue.
In the beginning, the navigationBar looks like it should.
After I rotate the device, the navigation bar keeps its height, while the status bar disappears.
When I rotate back, the navigation bar is now 44 points hight, like it should be in landscape.
I uploaded a small project to demonstrate the problem to you. I recognized that the Dropbox action extension has the same bug.
The view controller is embedded in a UINavigationController
I assume somewhere down the path forgot to call super.
Is there any workaround to fix this?
I was experiencing a similar issue. In my case I had a UINavigationController. I was presenting a view controller from a child view controller of UINavigationController. After presentation, when I rotated the device, the height of navigation bar was screwed up.
What I did
Instead of presenting a view controller from a child view controller of UINavigationController, I presented it from the UINavigationController itself. It fixed the problem.

How do I show a view over the tab bar but not over the navigation bar?

I want to present a modal view that shows over the UITabBar but not over the UINavigationBar.
From what I understand the best way to overlay a view on top of everything is to position it in its own UIWindow. This works great, and if I make the y origin of the view in the window lower than the navigation bar it works perfectly.
However, getting it lower than that y origin is really hard. I can use the topLayoutGuide.length property to position the y, but when I rotate that no longer is true as the navigation bar height changes.
How should I be doing this?
I had to deal with something similar recently, and ultimately to modally present a new view you'll be looking to call the navigation controller and then set its setDefinesPresentationContext: to Yes.
setDefinesPresentationContext: is needed so that a presenting view controller will restrict the bounds of a presented view to the visible area of the presenting view. As a result, the view controller is kept within the bounds of the currently visible window (The default is no, in which case the presented view keeps asking for a defining context up through the VC hierarchy until it reaches a VC that claims this role, or until it hits the UIWindow).
With this method, you won't have to calculate the bounds of your view, it'll just be done automagically. Check out the Apple docs on this method for the full explanation though.
(and shameless plug, I wrote about it on my blog. it's under "Presenting the Search Bar".. pardon the formatting, still a work in progress)

UITableViewContent Inset messed up on iOS 8

I have a navigation controller with a UITabBarController as the initial view controller. Within that, I have two UIViewController's as sub-viewcontrollers in the tab bar controller. Both of my view controllers have UITableView's in them. The first one always looks fine. However, the second view controller always has a messed up content inset. I don't know why because there doesn't seem to be any difference in the way I setup my table views. I can manually set the content inset in viewDidLoad, but there's got to be a better way since it's working by default in the first view controller.
This is the first table view. As you can see, the the content offset looks fine.
Something to note: when opaque navigation bars are turned off, the issue goes away.
This is the second table view. As you can see there is a table view cell underneath the navigation bar.
I fixed the issue by changing the structure of my view hierarchy. Apparently I should not of had a UINavigationController as the initial view controller, but rather had the UITabBarController as the initial view controller and from there have UINavigationControllers within the tab bar where needed.

Remove UIBarButtonItem from master view controller when detail view controller is visible

I am converting my view controllers into a split view controller with a Universal Storyboard to show two views on screen at the same time, which will only appear on iPad - only one will be visible on iPhone. I have a situation where a UIBarButtonItem is only relevant when only one view controllers is on screen. I want this button removed or hidden when both view controllers in the split view controller are visible.
I cannot use Size Classes to do this, since the button I want removed is in the master view controller (actually I have button in both the master and detail that should be removed), which won't have a size class of Regular w Regular h. Plus Interface Builder doesn't provide an "Installed" option for UIBarButtonItems, and I cannot check size classes in code because the app will also run on iOS 7.
How can I remove/hide a UIBarButtonItem when both the master and detail view controller are on screen? Or I could not add this button in IB, then add it in code when deemed appropriate, but how would I know if both view controllers will be on screen?
Here's a nice solution that works great for iOS 8 and iOS 7 on iPhone and iPad. You simply detect if there is a split view controller and if so, check if it's collapsed or not. If it's collapsed you know only one view controller is on screen. Knowing that info you can do anything you need to.
//remove right bar button item if more than one view controller is on screen
if (self.splitViewController) {
if ([UISplitViewController instancesRespondToSelector:#selector(isCollapsed)]) {
if (!self.splitViewController.collapsed) {
self.navigationController.navigationBar.topItem.rightBarButtonItem = nil;
}
} else {
self.navigationController.navigationBar.topItem.rightBarButtonItem = nil;
}
}

Using iOS 6 autolayout, what would be the proper way to display somthing above an UINavigationController?

In my app, i have a main view controller which sometimes brings a modal view on top of it. This modal view is a UINavigationController with a navigation bar. I want to display an image above the navigation bar, and have the navigation bar appear below the image.
I do not want to subclass anything and the app uses autolayout, i do not want a bunch of delegate callbacks and frame calculations. The view inside the navigation controller (the actual modal content) must still respond to different screen sizes correctly, such as rotation, call status bar etc. Also, no IB solutions please, these views are all managed in code.
How do i accomplish this?
I would turn off AutoLayout and place the image at the top
I don't think you can do it with your modal view being a navigation controller. I would do it by making that modal controller a UIViewController that you set up as a custom container controller. You can add an image view to the top of this controller's view and add the view of a child view controller (which would be a navigation controller) to the bottom. This would be a lot easier to do in a storyboard using container views, but it certainly can be done in code.

Resources