UIPopover get exact position on screen - ios

I have an iPad app in which I show an UIPopover view. I want to set the background of the popover depending on its position on the screen. Is it possible to get the exact position of the UIPopover relative to the screen?

try this
if ([myPopOverController isPopoverVisible]) {
CGPoint myPopOverPosition = [myPopOverController.contentViewController.view
convertPoint:myPopOverController.contentViewController.view.frame.origin
toView:mainTopView];
//If you set toView to nil then it will consider as the window or you could specify as yourappDelegate.window
}

Related

How to detect iPhone X home indicator?

The new iPhone X has gotten rid of the home button and replaced it with a "home indicator" at the very bottom that allows the user to swipe up to get back to the home screen.
My question is, how do we detect if this home indicator is on the screen? I want to do something like:
if (!notfullScreen)
{
if (swipeBarExists)
{
viewHeight -= swipeBarHeight;
}
}
I checked in [UIApplication sharedApplication] and found nothing. Basically I don't really know what to call this thing and am having trouble finding an answer.
You can utilize safeAreaInsets.bottom, defined for UIView to get the amount of space you should inset your content to ensure it doesn’t underlap the home indicator (or other elements). Note that this value may change, for example, when you rotate to landscape on iPhone it shrinks. To be notified when this occurs, implement safeAreaInsetsDidChange in your view controller. You can also utilize the safeAreaLayoutGuide with Auto Layout.
So, if you have a full screen view, you could check like so:
override func viewSafeAreaInsetsDidChange() {
super.viewSafeAreaInsetsDidChange()
if view.safeAreaInsets.bottom > 0 {
//home indicator
} else {
//no home indicator
}
}
Note that there is no API to get the height of just the home indicator bar itself.

Cannot detect tap after hiding tabbar

I am using iOS 7. I have a UITableView inside a UITabbarController.
I hide the tabbar using the following code (meanwhile I also set the tableView to be fullscreen)
CGRect frame = self.tabBarController.tabBar.frame;
frame.origin.y = 568.0;
self.tabBarController.tabBar.frame = frame;
However, after that, I cannot select the cell near the bottom. When tap at the position where the tabbar was, there is no effect.
Has anyone run into the same problem? Do anyone know how to fix?
You'll want to use something like This to detect the tab bar and then hide.

How do I make a custom tab bar which pops up when a button is pressed?

How can I create a custom popup tab bar. that has a small button and once pressed it appears from the bottm and it goes back when the small button get pressed again?
You can animate the position of a view by changing its center or frame property within an animation block. See here and here for documentation.
You essentially create your view off the screen, then animate it onto the screen:
// View is off the bottom of the screen
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,480,320,44)];
// Animate it onto the screen
[UIView animateWithDuration:0.25 animations:^{myView.frame = CGRectMake(0,436,320,44);}];
You could drag a TabBar in your interface from IB and set yourself as its delegate to respond to the selection of bar items. Since a TabBar is a view you should be able to animate it on/off the screen at the touch of a button.

popover shrinks to upper left corner when keyboard appears on iPad

I'm working on an app that has some forms that are contained within a popover. My problem is that when I click on any text entry field and the keyboard appears, the popover shrinks to the upper left hand corner of the screen (0,0) and you can't see the fields you are entering into. When you click the hide keyboard button, the popover returns to its normal size and position.
Is there any way to prevent popover resizing when the keyboard appears?
Here are screen shots in case my description is inadequate.
edit: Here is the code for how the popover is presented on the screen:
(void)displayPopoverForOrientation:(UIInterfaceOrientation)orientation {
if ([Utilities getAppDelegate].menuPopover) {
CGRect rect = CGRectMake(0, 0, 0, 0);
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
if (self.currentPopover == RESERVATIONS_POPOVER) {
rect = CGRectMake(365, 0, 0, 0);
} else if (self.currentPopover == ACCOUNT_POPOVER) {
rect = CGRectMake(600, 0, 0, 0);
} else if (self.currentPopover == RESORTS_POPOVER) {
rect = CGRectMake(0, 0, 0, 0);
}
}
[[Utilities getAppDelegate].menuPopover presentPopoverFromRect:rect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
Inside the popover is a separate view controller with the layout setup in a xib.
Feel free to ask any questions, I'm fairly new to iOS and Objective C, but I'm not new to coding so I'll do my best to clarify.
edit 2:
I've found that this only occurs in iOS 5. In older versions of iOS, the popover merely collapses vertically until there is enough room for the keyboard. Any ideas about about why this behavior has changed in iOS 5?
It's not possible to prevent the popover from changing shape when the keyboard appears. According to Apple's UIPopoverController docs:
The size you specify is just the preferred size for the popover’s view. The actual size may be altered to ensure that the popover fits on the screen and does not collide with the keyboard.
IOS will try to move it out of the way, but it may not be possible, depending on where you are presenting it from. For best results, present it from a bar button or from inside a scroll view (UITableView is ok), and design your UI so the popover is not too large (if the popover covers most of the screen, perhaps you should consider a segue to a modal view or similar). I found I needed to draw some diagrams so I could understand the layout better before I could get a solution that worked in all cases.
Actually it is very possible!... This is to do with the auto-Resizing that is ticked by default in IB:
I posted this on an another forum with similar question,.. The solution for me was to:
1) Go into the designer by
2) Opening the XIB ViewController that is causing the problem (i.e. the PopOver one).
3) Click to select it's VIEW.
4) Uncheck "AutoResizeSubviews"
5) When loading the PopOver in code, make sure you do:
6) Your_Popup_Window.popoverContentSize = Your_ViewController.view.bounds.size;
I hope this helps.
Kind Regards
Heider Sati

UIPopoverController Anchor Position

I have a UIPopOverController for which the content controller is a UINavigationController.
I'm resizing the popover size according to the content size of the controller pushed/popped into it. Initally i'm presenting the popover by using the method presentPopoverFromRect:inView:permittedArrowDirections:animated:. The anchor position is pointing at the center of the rect which i passed as an argument. If i push a controller(whose content size is small) into the navigationController , the popover shrinks from the bottom and moves above the rect which i mentioned earlier.
I tried to present the popover everytime(for push/pop) , anchor position remains # same point But the animation gets affected , doesnt looks good.
what needs to be done to make the anchor position remains same irrespective of the change in popover size variation ?
I've encountered the same issue and it seems that calling the presentPopoverFromRect method again will keep the anchor at the same position
e.g.
[self.myPopOver presentPopoverFromRect:rectOrigin inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
Hope it works in your case as well
Change frame after presenting UIPopoverController:
[popupController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:0 animated:YES];
CGRect popupFrame = popupController.contentViewController.view.superview.superview.superview.frame;
popupFrame.origin.y = btn.frame.origin.y + btn.frame.size.height+75;
popupController.contentViewController.view.superview.superview.superview.frame = popupFrame;

Resources