我试图在我的自定义键盘上添加Popover
,以便在长按按钮时显示替代表情符号,但我似乎无法让Popover成为自定义大小,它似乎显示为填充父视图的模态视图...
我的UIViewController初始化为:
self.popoverViewController = [[PopoverDetailViewController alloc] init];
self.popoverViewController.preferredContentSize = CGSizeMake(100, 50);
然后我按照这样处理长按:
- (void)longPress:(UILongPressGestureRecognizer*)gesture {
if (gesture.state == UIGestureRecognizerStateEnded ) {
self.popoverViewController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = [self.popoverViewController popoverPresentationController];
presentationController.permittedArrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
presentationController.sourceView = self.view;
presentationController.sourceRect = CGRectMake(30, 50, 10, 10);
[self presentViewController:self.popoverViewController animated: YES completion: nil];
}
}
理想情况下,我希望Popover
从长按按钮显示并具有自定义尺寸...
知道我需要改变什么吗?
答案 0 :(得分:1)
需要更多信息,但这可能是自适应演示风格的结果。默认情况下,至少在iPhone上,popover似乎全屏显示。
以下是一些代码,this tutorial也可能有所帮助。
self.popoverPresentationController.delegate = yourDelegate;
(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return UIModalPresentationNone;
}