Collection view alignment issue in different version - ios

Collection view moves up in iOS 10.3.3. But work fine in iOS 11.0.
Can any one let me know how to fix this kind of issue which is realted with version
CollectionView Constrains.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MSProductCategoryViewController
*msProductCategoryViewController = [storyBoard instantiateViewControllerWithIdentifier:#"MSProductCategoryViewController"];
msProductCategoryViewController.title =titleName;
[self.navigationController pushViewController:msProductCategoryViewController animated:YES];

For CollectionView moving up issue please check if you have unselected the "Adjust Scroll View Insets" property of your ViewController in storyboard.
Attributes Inspector of ViewController
You have added top constraint with 20 value. I assume you wanted to add top padding for collection view. If that is the reason then I suggest using "Section Insets" property of CollectionView.

Related

How to show one viewcontroller over other as overlay in iOS?

I have two view controller which Controller A and B. A controller displaying some info on screen. On top right of A screen I have a UIButton on click of button I want to show a help screen which will have some labels & when I touch the help screen it should go away.
I can do it by adding a view on top of all view & hide, show it. But I want to know how can I show HelpScreenViewController as a semitransparent view controller on top of first view controller on click of UIButton. When I tap on HelpScreenViewController it should go away.
EDIT:
I have added below code but does not work
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"TopOverVc"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];
Thanks in advance.
For what you described, you dont need a ViewController to contain the 'TopOver' view. A normal UIView would be better. Place that within your first ViewController, in interface builder. Drag it into your A ViewController class, along with the button. When the button is clicked, just show/hide your view containing the info you need.
You can use the containerView control and you can add the childViewController for it. You can use this as overlay by doing the background colors transparent as your needs.
This article may help help you http://spin.atomicobject.com/2015/07/21/ios-container-views/
One more thing, you can set this containerview hide/visible as you need.

JASidePanels fix right panel bounds

I am using JASidePanels to show a viewController on the right side of the screen.
The controllers are loaded from the Main storyboard in this manner from a JASidePanelController subclass:
-(void)awakeFromNib{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
TRMPracticeViewController *practiceVC = [mainStoryboard instantiateViewControllerWithIdentifier:#"Practice"];
TRMPracticeSetupViewController *practiceSetup = [mainStoryboard instantiateViewControllerWithIdentifier:#"PracticeSetupVC"];
[self setCenterPanel:practiceVC];
[self setRightPanel:practiceSetup];
[self setRightFixedWidth:practiceVC.view.frame.size.width/3.0f];
}
The TRMPracticeSetupViewController has a fixed frame in the storyboard of 200px x 320 px and I would like to maintain the width once the controller is loaded and added to the side (or at least a width proportional to the size of the screen).
However, once the vc has been loaded and added, its frame is set equal to the center view controller, which has of course the size of the screen. So, the views inside the right vc, go under the center vc because of the auto layout constraints that fix their margin to the container bounds.
How can I fix the right panel bounds width to e.g. 200px ?
JASidePanelController has a method for setting fixed width of either left or right panel. Just add this to your code:
self.rightFixedWidth = 200.0f;

UIView in xib displays as portrait when opened in landscape

I just added a separate view controller and xib in a project that uses storyboards throughout. I display it from inside another view controller with the usual code:
OtherVC *othervc = [[OtherVC alloc] initWithNibName:nil bundle:nil];
[self.view addSubView: othervc.view];
In portrait orientation, he xib displays and auto rotates properly right out of the box.
But when I display it when the iPad is already in landscape, the size of the view is portrait and positioned off to the left.
What's going on? There doesn't seem to be a way to add constraints to the view.
Thanks!
This is not the right way to present a separate viewController.
The problem is that you are adding a view on the actual view..but this view have a certain frame that will remain the same when you add it on the view..in both case (landscape and protrait). So, to understand, you should check the orientation and then set the frame of the view properly. But as i said, the way that you are using is wrong.
In your case you should use segue from storyboard.
Or, at max, by code but with something like:
OtherVC *othervc = [self.storyboard instantiateViewControllerWithIdentifier:#"Identifier"];
[self presentViewController:othervc animated:YES completion:nil];
where Identifier is set in your viewController in the storyboard by the inspector panel at the right.
Or, if you instead wanted to say "NIB" you should to do:
OtherVC *othervc = [[OtherVC alloc] initWithNibName:#"yourNibName" bundle:[NSBundle mainBundle]]; //Or your correct bundle but i guess will be this.
[self presentViewController:othervc animated:YES completion:nil];
So after this, if you are sure to have set both orientation on your project, your view will be in landscape.
Now you will use AutoLayout or normal mask rules without AutoLayout to manage the elements on the view.

Add a UINavigationController nested inside a container view controller to a UITabBarController

I have a UIViewController (red) set as the first tab of a UITabBarController as shown in the storyboard below. This view controller is a container view controller and loads a UINavigationController inside its contentView (the white rectangle inside the red view controller).
This is my code for loading the navigation controller inside the red view controller's contentView:
- (void)viewDidLoad
{
[super viewDidLoad];
// instantiate navigation controller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navigationVC = [storyboard instantiateViewControllerWithIdentifier:#"N"];
// place navigation controller inside content view
[self addChildViewController:navigationVC];
navigationVC.view.frame = self.containerView.bounds;
[self.containerView addSubview:navigationVC.view];
[navigationVC didMoveToParentViewController:self];
}
From what I know about view controller containment this should work as I am explicitly setting the frame for the navigation controller. However, when there are enough cells in the tableView to exceed the container's height there is always a bar at the end of the tableView when I scroll down. I have set the tableView's backgroundColor to orange and the cell's backgroundColor to white in order to see the difference.
How do I get rid of that orange gap at the end of the tableView?
(Note: I am not using autolayout and I need a solution that works for both - iOS7 and iOS6.)
I know you are also looking for an answer which works on iOS 6, but on iOS 7 and above you can use
self.extendedLayoutIncludesOpaqueBars = YES;
Have you tried setting self.edgesForExtendedLayout = UIRectEdgeAll; in -(void)viewDidLoad of Table View Controller - Root?
Note: iOS 7 only

Resize UITableViewController for display in a popover

I have a UITableViewController that I am trying to display in a UIPopoverController. No matter what do, the tableview is always displayed at full size within the popover.
In my StoryBoard I've set the UITableViewController's Size to Freeform. I've explicitly set the UITableView's height and width in the Size inspector.
Here is how I setup the controller and popover:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard-iPad" bundle:nil];
self.settingsController = [sb instantiateViewControllerWithIdentifier:#"SettingsViewControllerID"];
self.settingsPopover = [[UIPopoverController alloc] initWithContentViewController:_settingsController];
I've also tried setting the controller's popover size explicitly:
self.settingsController.contentSizeForViewInPopover = CGSizeMake(400.0, 400.0);
When I run the app and activate the popover - it is almost as tall as the main screen.
Am I missing something obvious here?
Thanks in advance,
CS
You can change the tableView size by using below code.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIStoryboardPopoverSegue *popoverSegue;
popoverSegue = (UIStoryboardPopoverSegue *)segue;
UIPopoverController *popOverController = popoverSegue.popoverController;
[_popOverController setPopoverContentSize:CGSizeMake(width, height)];
}
The UITableViewController always wants to be the full size of the window, or popover (which is a special kind of window). If you want a smaller table view, use a UIViewController instead as the content controller of your popover. You should then be able to resize it in IB.

Resources