Reposition UIActionSheet on iPad - ios

I have a UIActionSheet which appears as a UIPopoverController on the iPad. I am trying to show it from a UIButton by using:
[self.exampleActionSheet showFromRect:self.exampleButton.frame inView:self.view animated:YES];
What I am trying to do now is to reposition this UIActionSheet on orientation change. But when I use the above code to reposition after the screen has rotated, it doesn't do so. Can anyone tell me how to do this properly?

A better workflow would be:
Dismiss actionsheet when a rotation occurs
Calculate the new rectangle where it should be presented from
Present a new actionsheet from the new rectangle

Related

UIPopoverController backgroundColor back to default after rotation on iOS 8

When setting backgroundColor to [UIColor blackColor] to a UIPopoverController everything is fine and presents correctly on iOS7 and iOS8.
I present it via
[aPopover presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
After a device rotation, the popover backgroundColor is reset to default color (white in this case).
This does not happend in iOS 7. Only on iOS 8
I have already tried with
- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
and a repositioning using UIPopoverControllerDelegate and the same problem occurs.
Last information : I had this problem only when displaying the popover on a UINavigationBar but not when presenting it on a regular UIView or any UIButton.
Thanks for your help
I also had such problem with popover on iOS8. Besides rotation the background colour was reset when popover changed its size (e.g. when keyboard shows up to edit some text field in the popover).
The key observation is that the issue usually happens with popovers that have its arrow on the very content's edge (and this is the case when presenting popover from UIBarButtonItem of full screen view controller).
Hence my workaround was to modify sourceRect just enough for the popover's arrow to move away from its corner. For example in my particular case I had a bar button item with custom 33x33 view (which was used as sourceView) and the issue was fixed by setting sourceRect to {20, 30, 0, 0} instead of custom view's bounds (though I suppose the exact required offset may depend on popover's size).
For iOS 8.2 (xcode 6.2) : i have problem while open keyboard, popovercontroller becomes white. and after keyboard disappears it is also same as white background.
i use following code to resolve my issue.
[objPopovercontroller presentPopoverFromRect:CGRectOffset(CGRectMake(SCREEN_WIDTH-40, 60, 0, 0), -1, 0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
// SCREEN_WIDTH = (IS_IPAD?1024:[UIScreen mainScreen].bounds.size.width)
I also had this problem in iOS 9.1. Offsetting the source rect was a good observation and workaround but for me it didn't seem to have an effect until the offset reached 16 or so, which meant the arrow looked somewhat mis-placed.
To avoid this, in the end I used GIKPopoverBackgroundView to provide a custom background view (UIPopoverBackgroundView). I extracted the relevant popover background images from UIKit (see [1] below) to get the same popover shape as iOS 9 and modified their colour to suit my needs.
Heavy-handed, and a bit fiddly setting up the cap insets for the images, but it did the trick.
[1] Use cartool to get _UIPopoverViewBlurMaskBackground* from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/UIKit.framework/Artwork.bundle/Assets.car

UIPopOverController appears in wrong place

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.

iPad application, changing popover dimensions whilst view is loaded

I have an app in which its my intention to change screen orientation as the user rotates the iPad. In my app I have several popovers.
The potential issue I'm concerned about is one of my popovers covers most the screen so if rotation changes, I'd want the popover to change view dimensions. Is it possible whilst a view is open or will i have to close it and reopen it.
Thanks
If your using a UIPopoverController the standard behaviour it does is to hide the popover when you rotate. It try's to then reposition it for you, this tends not to work so you want to use popoverController:willRepositionPopoverToRect:inView to set your new position and resize as needed.
If you use setPopoverContentSize:animated: it will re size for you, If your using autolayout you'll want to use preferredContentSize in the content viewController.
Apple Doc:
If the user rotates the device while a popover is visible, the popover
controller hides the popover and then shows it again at the end of the
rotation. The popover controller attempts to position the popover
appropriately for you but you can also implement the
popoverController:willRepositionPopoverToRect:inView: method in the
popover delegate to specify a new position.

Centralize popover display in xcode

My popover border was only partially showing the view I wanted to display, so I used the line self.buttonPopoverControllerH1.popoverContentSize = CGSizeMake(1000, 700); to enlarge it.
While it did enlarge the popover, the view still isn't central, and so it is still only partially displayed. Does anyone know how to rectify this?
I can't use autolayout as I'm developing an app for ios 5. I can't link in an image as I don't have enough rep, but
is what I'm talking about. Only half the view is displayed.
Set the rect when you present it..just modify to fit the frame you would like:
CGRect rect = CGRectMake(350,100,100,100);
[yourPopoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Do you want the popover view to take up most of the screen? If so, you should consider using a Modal View, instead of a popover view. Popover views shouldn't really cover the entire screen.

uipopovercontroller animation like in iPad Maps.app

I'm wondering how to make the same popover animation as in Maps.app on iPad. It seems the popover grows in 2-directions at the same time.
Thanks in advance.

Resources