一些代码
-(IBAction)addbutton:(UIToolbar *)sender;
{
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
popoverView.backgroundColor = [UIColor blackColor];
/*
* Adding buttons programaticly to popout view
* button code etc
*/
popoverContent.contentSizeForViewInPopover = CGSizeMake(400, 300);
//create a popover controller
self.popoverController = [[[UIPopoverController alloc]
initWithContentViewController:popoverContent] autorelease];
[popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
谢谢
答案 0 :(得分:2)
您的popoverButton
可能不是self.view
的子视图,因此使用其相对于frame
的子视图会导致矩形不正确。使用popoverButton.bounds
代替矩形,popoverButton
代替fromView
参数。
请注意,fromView
参数不确定将在哪个视图中显示弹出窗口(它始终位于所有内容之上),而是 relative 视图的坐标系应该解释矩形。
答案 1 :(得分:0)
[popoverController presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
尝试更改框架popRect
。