Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
If you're annoyed about the incorrect arrow presentation on popovers (https://twitter.com/steipete/status/624521051855319040) use this category. Oh, and file a radar! I did.
@implementation UIPopoverPresentationController (PSPDFAdditions)
+ (void)load {
PSPDFSwizzleMethodImplementation(self, @selector(containerViewWillLayoutSubviews), ^(UIPopoverPresentationController *_self) {
// Refresh bar button view internals
[_self pspdf_updateBarButtonView];
((void( *)(id, SEL))objc_msgSend)(_self, PSPDFPrefixedSelector(containerViewWillLayoutSubviews));
});
}
// UIPopover positioning from barButtonItems is broken, fix it.
- (void)setPspdf_barButtonItem:(UIBarButtonItem *)barButtonItem {
objc_setAssociatedObject(self, @selector(pspdf_barButtonItem), barButtonItem, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self pspdf_updateBarButtonView];
}
- (void)pspdf_updateBarButtonView {
UIBarButtonItem *barButtomItem = self.pspdf_barButtonItem;
if (!barButtomItem) return;
UIView *itemView = barButtomItem.pspdf_view;
if ([itemView isKindOfClass:UIView.class]) {
CGRect itemRect = itemView.frame;
CGRect navBarRect = itemView.superview.frame;
if (navBarRect.origin.y < 100.f) {
itemRect.origin.y -= 5.f;
}
itemRect.origin.x -= 1.f;
self.sourceView = itemView.superview;
self.sourceRect = itemRect;
} else {
self.barButtonItem = barButtomItem;
}
}
@end
@steipete

This comment has been minimized.

Copy link
Owner Author

commented Jul 29, 2015

Oh, you'll need to replace the swizzling above with whatever helper you have - there are many ways to fix. If you don't update the toolbar on rotation, you can skip the swizzling completely. Ah, and use your own prefix, or you'll clash with PSPDFKit (if you ever need to display/edit PDFs on iOS or Android...) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.