我在我的应用程序中使用弹出窗口视图,当我浏览示例时,我发现如何创建弹出窗口视图,但在示例代码中,弹出窗口视图将显示到整个页面。当我点击按钮时,我想要指定宽度和高度的弹框。
-(IBAction) settingsGo:(id) sender{
NSLog(@"Go");
if(self.popoverController == nil)
{
PopOver *lang = [[PopOver alloc]
initWithNibName:@"PopOver" bundle:[NSBundle mainBundle]];
UIPopoverController *popOver =
[[UIPopoverController alloc]initWithContentViewController:lang];
popOver.delegate = self;
[lang release];
self.popoverController = popOver;
[popOver release];
}
CGRect popoverRect = [self.view convertRect:[button frame]fromView:[button superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 50);
[self. popoverController
presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
所以我应该在上面的代码中做出哪些更改,以获得指定大小的宽度和高度的帧。
答案 0 :(得分:5)
帐户是要显示的类。 popAccount是它的实例。 buttonA是点击后将显示popOver的按钮。
-(void)viewDidLoad
{
popAccount = [[Account alloc] init];
//[popAccount setDelegate:self];
popOverControllerA = [[UIPopoverController alloc] initWithContentViewController:popAccount];
popOverControllerA.popoverContentSize = CGSizeMake(200, 200);
}
-(IBAction)togglePopOverControllerA {
if ([popOverControllerA isPopoverVisible]) {
[popOverControllerA dismissPopoverAnimated:YES];
} else {
[popOverControllerA presentPopoverFromRect:buttonA.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
进一步询问任何疑问..
答案 1 :(得分:2)
将popoverController.popoverContentSize
设置为您想要的任何大小。
答案 2 :(得分:1)
在根视图中定位
CGRect frame= CGRectMake(0,0, 0, 0);
[self.myPickerPopover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:0 animated:NO];
在弹出框中显示的视图控制器内容中调整大小
-(void)viewDidLoad
{
self.contentSizeForViewInPopover = CGSizeMake(750,880);
}