I can't keep popover the same position on the screen after rotation. Is there any good way to do that, because just setting some frame to popover works terrible after rotating.popover.frame = CGRectMake(someFrame);
After rotation popover looks fine only if it is in the center of the screen.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
As of iOS 8.0.2 willRotateToInterfaceOrientation will not have any effect. As mhrrt mentioned, you need to use the delegate method:
- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing *)view
So for example if you want your popover to appear directly below a button that was pressed, you would use the following code:
UIPopoverController
was deprecated in ios9 in favor of UIPopoverPresentationController introduced in ios8. (I went through this transition also when going fromUIActionSheet
toUIAlertController
.) You have two choices (example in obj-C):A. Implement the
UIViewController
method below (UIKit calls this method before changing the size of a presented view controller’s view).B. Alternatively, when configuring your
UIPopoverPresentationController
to present, also set its delegate. e.g. your presenting vc can implementUIPopoverPresentationControllerDelegate
and assign itself as the delegate. Then implement the delegate method:I've tried just to set new rect (rect.initialize(...)) and it works.
I had a same problem. Instead of performing
-presentPopoverFromRect
each time by keeping track of the source rectangle / view from which it is presented, I subclassedUIPopoverController
. After doing it, all you have to do is set either the UIBarButtonItem / UIView from where the popover has to be displayed. You can even opt for displaying the popover from custom frame which can be passed in as a NSString value.CSPopoverController.h:
CSPopoverController.m:
Usage:
If it is a UIBarButtonItem from where you are presenting it:
If it is a UIView from where you are presenting the popover:
You can do this in
didRotateFromInterfaceOrientation:
method of the view controller that you used to present the popover.Use
setPopoverContentSize:animated:
method for setting the size of the popover.I have similar problem which I resolve by this
Where
myfield
is frame from which you want to show your popover andmyscrollview
is container view in which you add your popover as subview(in my case its my scrollview, instead of puttinginView:self.view
I useinView:myscrollview
).