UIPopOverController appears in wrong place - ios

So I have this UIButton, when clicked it triggers a UIPopOverController.
The UIButton is located in a Bar Button Item, in a Toolbar that has a 960 value for y. An iPad view.
My problem is, this button shows the PopOver at the top of the screen, whilst another button on the same toolbar shows the PopOver correctly (direction up).
I tried forcing the direction and changing buttons location on the toolbar but it didn't work. I tried the frame value for the toolbar but that brings it only from the middle. Here is the code for button action.
[self.popOverController setContentViewController:self.legendViewController];
[_popOverController presentPopoverFromRect:self.btnLegend.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES ];
I know that there could be a few functional ways of doing this. I am starting to think that this specific UIButton is cursed.

You should try the bar button presentation method.
When using presentPopoverFromRect:inView: the frame provided would usually be your button (as you have it) but the view would be the button superview (not the root view). This is because the frame needs to amen something in the coordinate space of the provided view.

Related

Show menu controller on top of cell in iOS collection view

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];

UIBarButtonItem setTitlePositionAdjustment on iOS 7 Navigation Bar

I have a UINavigationBar that has a new height of 85 and is fixed for landscape and portrait. I am adding an edit button at the top right corner but it wont stay there.
I've used the following:
[item setTitlePositionAdjustment:UIOffsetMake(0, -47) forBarMetrics:UIBarMetricsDefault];
But, if I rotate the device it moves back down 47 to the original location. If I change the metrics again it moves back to the original location. If I replace the button with another button it moves the new button to the original location, and setting the position for the new button does nothing.
I can't figure out how to move the button and get it to stay. There's no way to use constraints on the UIBarButtonItem.
You could try to put a UIView in the top right corner as the UINavigationBar child. Make the UIView have the same height as the navigation bar, and put your button inside the view. You can then add constraints for the button inside the view.

Area under UINavigationBar does not respond to taps when frame is moved offscreen

I currently have a navigation controller with a UINavBar within my view controller. I hide the navbar by changing the frame x position to a negative value. This hide's the navbar but the area under the navbar no longer responds to touch input. How can I fix this?
You could hide the navigation controller with
[self.navigationController setNavigationBarHidden:YES animated:YES];
That way your view will resize.
An easier (and more intuitive) way is to simply modify the View Controller settings. You can remove the NavBar by going to the Utilities menu, selecting the Attributes Inspector, and then setting "Top Bar" to None. Be sure you have the right View Controller selected in the Storyboard.
Obviously this won't do you any good if you're not using a storyboard. In that case, use Danilo's solution.

Present UIPopoverController from a moving rect

Just got this weird problem, where I have a scroll view and buttons in the scroll view. I want to display a UIPopover from the button when touched, with UITextFields inside the UIPopover. The problem comes when the Keyboard appears. In certain cases, when the UIButton is so high in the view that the popover can only be displayed under it with the UIPopoverArrowDirectionUp, and when keyboard pops in, this popover cannot move any more up and therefore magically disappears to the top left corner (probably some Apple thing).
My solution is to check the frame of the UIPopover and to check that there is enough space for the keyboard, and if not, scroll the UIScrollView up with the buttons as well in order to be able to push the UIPopover up and so make sure that both the Keyboard and the popover fit.
So the question is: Is it possible to move the popover as the button moves?
Thanks

iPad popover not resizing properly after search keyboard is dismissed

I have a popover that contains a tableview (which is inside a navigation controller) with custom cells and a search bar in the header. Once I enter the search bar the popover shrinks appropriately to make room for the keyboard. Good so far. Once I dismiss the keyboard either by pressing the search button or the dismiss keyboard button, the popover appears to resize a little but does not does return to the full length as I would expect. I've tried all the suggestions to update the popoversize and contentsizeinpopover. They seem to have no effect.
Any thoughts or workarounds?
Thanks,
Rob

Resources