我有一个显示弹出窗口的按钮。弹出窗口必须出现在按钮下方。但它出现在屏幕上的某个地方。
这是弹出窗口的我的代码
UIView *popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320,340)];
[popoverView addSubview:tblViewMenu];
popoverContent.view = popoverView;
popoverContent .contentSizeForViewInPopover = CGSizeMake(620,620);
popPickerController = [[UIPopoverController alloc]initWithContentViewController:popoverContent];
[popPickerController presentPopoverFromRect:anchor.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUpanimated:YES];
顺便说一下,这个popover会显示在一个滚动视图中。
答案 0 :(得分:3)
将以下代码用于当前的popoverView。
[popover presentPopoverFromRect:button.frame inView:self.scrollView permittedArrowDirections: UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp animated:YES];
答案 1 :(得分:3)
将按钮的直接父级作为参数值inView:
[popPickerController presentPopoverFromRect:anchor.frame
inView:anchor.superview
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
始终确保在呈现popover时给予正确的父母。
答案 2 :(得分:0)
[ur popovername presentPopoverFromRect:[(UIButton *)sender frame] inView:anchor.superview allowedArrowDirections:UIPopoverArrowDirectionUp animated:YES];