我在UIPickerView
内显示UIPopoverController
。 UIPickerView
的尺寸为:320x216
。出于某种原因,UIPickerView
似乎是正确高度的约3/5,而UIPopoverController
一直向下延伸到屏幕的底部。
请参阅以下代码。
谢谢!
self.picker = [[[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)] autorelease];
self.picker.backgroundColor = [UIColor clearColor];
self.picker.showsSelectionIndicator = YES;
self.picker.delegate = self;
self.picker.dataSource = self;
self.picker.transform = CGAffineTransformMakeScale(-1, 1);
UIViewController *pickerController = [[UIViewController alloc] init];
[pickerController setView:self.picker];
UIPopoverController *pickerPopover = [[UIPopoverController alloc] initWithContentViewController:pickerController];
[pickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
pickerPopover.delegate = self;
self.popover = pickerPopover;
[pickerController release];
[pickerPopover release];
答案 0 :(得分:8)
“压扁”选择器视图的原因似乎是这一行:
[pickerController setView:self.picker];
相反,将选择器视图添加为子视图:
[pickerController.view addSubview:picker];
接下来,要修复弹出窗口高度,请在显示之前设置popoverContentSize
:
pickerPopover.popoverContentSize = picker.frame.size;
另外,修复选择器视图的框架:
CGRectMake(0, self.view.bounds.size.height+44, 320, 216)
到此:
CGRectMake(0, 0, 320, 216)