Show menu controller on top of cell in iOS collection view - ios

I want to show a UIMenuController with custom actions when the user long pressed on a cell in the collection view which is embedded in container view.
I have implemented as mentioned in this stack overflow solution which is working fine. Copy Callout in UICollectionView
The problem I have now is menu items are coming below the cell even though I kept the arrow direction to UIMenuControllerArrowDown.
My collection view is part of a container view which is inside a view controller. When I press on an image in the collection view, it is showing the menu item on the bottom of the cell. How can I show it on the top?
I tried to show it in a particular view as below, but my effort got no use.
[menu setTargetRect:cell.bounds inView:parentControllerView];
Can someone suggest how I can resolve this problem? Let me know if my question is not clear or needs more details.

Your menu is showing bottom of the cell as you have set the cell's parent view to display menu, the parent view's height is not capable to display your menu below your cell, so it is displaying overlapping your cell.
So if you want to show your menu below your cell not no it you have to change the view in which menu is showing..set
[menu setTargetRect:cell.bounds inView:[UIApplication sharedApplication] window];
this will display your menu in main window of application.

The problem arises when you try to present the menu above a view that would result in the menu appearing overtop the navigation bar. iOS doesn't want to show it overtop the nav bar, and instead will push it down. If your items were lower on the screen, it would properly appear above the view and point down to it as expected. It may be worth filing a bug report at bugreport.apple.com to request the menu appear overtop the navigation bar.
Also, it is good to use the cell's bounds as the target rect, and the cell for the view as opposed to the parent controller's view, like so:
[menu setTargetRect:cell.bounds inView:cell];
Now, I have found a workaround to force the menu to appear over the navigation bar. Instead of providing the cell's bounds as the target rect, push it down a little bit yourself. For some reason, doing this will prevent iOS from pushing it down when it would appear over the navigation bar.
[menu setTargetRect:CGRectMake(0, 10, cell.bounds.width, cell.bounds.height - 10) inView:cell];

Related

Remove the gray bar at the bottom of view controller - iOS

The image shows the View controller and the bar I want to remove. And also the structure of the view controller:
Someone told me how to remove the grey bar present at the bottom of the view controller as shown in the image. Unable to select and delete the bar. When I try to add the tab bar in that place, it goes behind the grey bar and becomes invisible.
What do your simulated metrics look like?
Can you get rid of the bar by changing the bottom setting?
Couple of things - if you are using autolayout, just make a constraint to the bottom of the container, with 0 value for the constraint. That will take it to the bottom. Second thing I would add is a zero size table view footer to the tableview.
This is a toolbar that comes with the UINavigationController that the View Controller is embedded in. Assuming you have a Navigation Controller on the storyboard connected to the view controller, select it and in the attributes inspector deselect "Shows Toolbar". If you want to do this in code you can get and set isToolbarHidden on a UINavigationController instance.

How to design a tabbar inside a view

I need to make this view:
A view on top of the tab bar with some data. (image, name, text, ...)
tab bar has a 3 page and every page has a separate view
When user scroll up, tabbar will be scrolling top of the page and a UILable stands top of tab bar. It can be show with some fading animation (not important right now)
this is after scrolling:
I search in cocopods but I didn't find solution.
---- EDITE
I want to know how to put uitabbar inside a view. Is it possible ?
If yes, How to change just sub view of tab bar when I change tab bars!
I want to know how to put uitabbar inside a view. Is it possible ? If yes, How to change just sub view of tab bar when I change tab bars!
Yes, but I wouldn't describe the thing you are showing in your screen shot as a "tab bar". It is a UISegmentedControl. So all you have to do is respond to the user tapping on a segment of the UISegmentedControl by substituting one view for another, and that's easy to do.

Drawing my view on top of navigation bar

Can I draw my custom view on top of navigation bar? I am trying to get a control like Google chrome's more button.
I see you are using kxmenu for drawing the view.
Instead of drawing the menu in self.view, draw it in screen window.That way, you could draw over the navigation bar.
Further, to exactly replicate the Google's popup action. Follow these steps
1. Create a tableview, populate with options, Give a header view with the share, reload, and favourite menus
Find the touch point on the screen, i.e, in your case, the centre of the right bar button
Add the table to
[UIApplication sharedApplication].keyWindow
Animate the table

Show first cell in UITableView just under the Topbar

I have an UITableView in a ordinary View controller with the Top-bar visible on an iPhone.
However, as per the screenshot below, the first cell in the table view is behind the Top-bar. How can I make it appear under the Top-bar while on the iPad, which doesn't use the navigation controller, and doesn't have the Top-bar it appears at the top?
if you use storyboards there is a nice option on the right (see screenshot). it is called extend edges - under top bars. if you clear the checkbox, your problem should be solved.

ios interface builder layout oddity

I'm using XCode+IB to layout a pretty simple view. There is a standard NavigationController navigation bar at the top. Inside the main View is another View which contains a Label, and then a table below that takes up the rest of the screen. I put the label in this container view because I want that area below the navigation bar to have a background color (gray).
The problem is that even though the main View starts just below the navigationBar, the label's container view is exists underneath the navigation bar. Sort of. You see, the label appears below the nav bar, but the gray background is somehow under the navigation bar. If I set the height of the label's view to be 75px, it just starts to appear below the navigation bar. (22+44 for statusbar and navigation bar)
Auto-layout is disabled.
So why is the View container starting below the navigation bar for the background? (but not its internal label?)
Since IOS7, I use this in the ViewController so that the content starts below the navigation bar, instead of underneath it.
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]){
self.edgesForExtendedLayout = UIRectEdgeNone;
}
I realize alternatively I can set the main view's background or make the label especially large perhaps and give it a background, but I'd like to see why this isn't working first.
EDIT:
I added a feature to this View where the main view will shift upwards 125px when the keyboard is opened for some UITextFields. Interestingly, the entire view shifted except for the Label's View container. That view remained in place while it's parent view shifted up and back. The label itself shifted up and down however. So once again, the middle View seems linked to the Window, and not the actual main View...
Check if you have Adjust Scroll view Insets on!
Go to your view controller, and it is under the Attributes Inspector
You might want to consider a header cell if you just want to be able to post a message or instructions just below the nav bar. You can then avoid the extra UIView thing. The header cell will not scroll with the table view if that is your concern and it will position just below nav and above the rest of the table cells. Here is a simplified example that uses a custom header cell setting the background color. You can also drop UILabels, etc. into the cell via IB if you choose.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
MyCustomHeaderCell *headerCell = [tableView dequeueReusableCellWithIdentifier:#"MyCustomHeaderCell"];
headerCell.backgroundColor = [UIColor grayColor];
return headerCell;
}

Resources