I am having trouble with setting the size and position of a UIPopOver without an arrow.
What i am trying to do is to bring up a popover view on the top left of the iPad screen and also have the content size that i have set.
I get different content size for the popover when i use an arrow and when i not. When i use the following code:
CGRect rec = CGRectMake(0, 0, 1, 1);
[self.displayOpPopover presentPopoverFromRect:rec inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
The result is:
and when i do:
[self.displayOpPopover presentPopoverFromRect:rec inView:self.view permittedArrowDirections:0 animated:YES];
The result is :
I have set 'use explicit size' for popovers in the storyboard (which is the size of the view when i have an arrow).
But the view somehow resizes itself when the arrow direction is 0.
Any suggestions as to how should i set the popover to the top left without an arrow.
Thanks !
Related
I noticed that with a NavigationController on an iPhone, the height is 460. So it includes the whole screen except the status bar.
However, when I add something at coordinate 0, it shows up after the NavigationBar, although the size of the navigation bar is included in the height (meaning the entire frame of this view sticks off the screen).
Did I make a mistake? If not, why is it structured this way?
NSLog(#"Frame: %#", [NSValue valueWithCGRect: self.view.frame]); // prints {(0, 20), (320, 460)}
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.width, 50)];
[self.view addSubview: scrollView]; // showing up 44px *after* the nav bar
I already answered your other similar question, but here is one for this.
In viewDidLoad you will see the views height as 460 because at that point it hasn't resized to account for the Nav Bar.
But If you printed the same frame out in say viewWillAppear you will see that now the frames height has adjusted for the Nav Bar.
So if you want to add something in viewDidLoad, you need to add it based on the views frame, add whichever resizing mask will do the job you want, and see it adjust correctly once the view appears.
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
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;
I have a tabbar app, and I want a popover to come from one of the tabs. Is there a good/easy way to do this without changing views?
There isn't currently a way to directly (through a supported api call) get the frame of a specific tab bar item. What I do is just show the popup from the left end of the tab bar like this:
CGFloat tabBarHeight = self.tabBarController.tabBar.bounds.size.height;
CGRect rect = CGRectMake(0, 0, tabBarHeight, tabBarHeight);
[popoverController presentPopoverFromRect:rect
inView:self.tabBarController.tabBar
permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
You could try to estimate the position of the tab bar item taking the current orientation into account if you really wanted to and adjust the X coordinate of the rect above.
You could also look through the subviews of the tabbar and find the UITabBarButton object but that's not documented so it's not recommended.
I would like to create a new keyboard for the iPad.
I have designed a view that has the keys and all the underlying work to fill in a textbox as the user presses the keys, and passes the value back to the calling routine when the user presses the return button.
This all works ok.
Now - I want to create this view as a popover.
I have the basic operations complete (pops up and is dismissed)
But now I need some fine tuning help.
Here are my questions...
1) How do I create a popover window centered on the screen without a UIPopoverArrowDirectionAny selection?
2) Ensure the popover window is the size that I created it with in the XIB file (currently, it resizes and removes some of the rightmost size of the window)
Thanks
tony
To present it with no arrows pass 0 for "permittedArrowDirections":
[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];
To center it, pass a 1x1 rect located at the center of your view:
CGRect rect = CGRectMake(viewWidth/2, viewHeight/2, 1, 1);
[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];
Then you have a centered and arrow-free popover.
The bit about removing the arrow could break at any time. They didn't provide a UIPopoverArrowDirectionNone option for a reason, they may choose to throw an exception in the future when 0 is passed, or default to something. Use it at your own risk.
If you are using a UIPopoverController, it will have an arrow. Here are your choices.
UIPopoverArrowDirectionAny
UIPopoverArrowDirectionUp
UIPopoverArrowDirectionDown
UIPopoverArrowDirectionLeft
UIPopoverArrowDirectionRight
As you can see there is no UIPopoverArrowDirectionNone
As for the XIB size, in your ViewDidLoad Method of the implementation file, you can set the following.
self.contentSizeForViewInPopover = CGSizeMake(320.0, 360.0);
You can set the size any way you like for the popover.
I've just been working this one out but wanted to do as much in the storyboard as possible which changes the approach a bit:
1) Select the popover in the storyboard and un-tick Directions Up/Down/Left/Right to get rid of the arrows.
To center it on screen override prepare for segue and do something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
CGFloat horizontalInset = (self.view.frame.size.width - popover.popoverController.popoverContentSize.width) / (CGFloat)2.0;
CGFloat verticalInset = (self.view.frame.size.height - popover.popoverController.popoverContentSize.height) / (CGFloat)2.0;
popover.popoverController.popoverLayoutMargins =
UIEdgeInsetsMake(
verticalInset,
horizontalInset,
verticalInset,
horizontalInset);
}
In my case I also found that the popover segue's corner radius didn't match my design so I change the background color to clear to sort that out i.e. add this to the above block:
popover.popoverController.backgroundColor = [UIColor clearColor];
2) In the destination controller for the segue find the attribute 'Popover' and tick 'Use Explicit Size' and put the size of you want it to appear in popover mode.