0

我想将工具栏和选择器视图作为 popovercontroller 的子视图,为此我执行以下操作,到目前为止,我的选择器视图显示完美,但在上面我还想显示我的工具栏,其中有一个名为 Done 的按钮如果您发现我做错了什么,请指导我

- (IBAction)setAlarm:(id)sender {

    UIViewController* popoverContent = [[UIViewController alloc] init];
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
    popoverView.backgroundColor = [UIColor whiteColor];


    [popoverView addSubview:toolbar];
    [popoverView addSubview:timePicker];

    timePicker.hidden = NO;
    toolbar.hidden = NO;

    popoverContent.view = popoverView;

    //resize the popover view shown
    //in the current view to the view's size
    popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 216);

    //create a popover controller
    popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    timePicker.frame = popoverView.bounds;
    toolbar.frame    = popoverView.bounds;

    CGRect popoverRect ;
    popoverRect.origin.x =591;
    popoverRect.origin.y = 139;
    popoverRect.size.height = 95;
    popoverRect.size.width = 44;

    [popoverController presentPopoverFromRect:popoverRect
                                       inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionUp
                                     animated:YES];

    //release the popover content
    [popoverView release];
    [popoverContent release];

    timePicker.hidden = NO;
    toolbar.hidden = NO;


}
4

1 回答 1

1

问题是您将展位子视图的框架设置为相同的值:

timePicker.frame = popoverView.bounds;
toolbar.frame    = popoverView.bounds;

因此,首先添加的将隐藏在另一个之后。您需要设置框架,以便工具栏正确定位在选择器上方(并调整弹出框的大小以允许它们两个空间)。


就像是:

CGRect toolbarFrame = toolbar.frame;
toolbarFrame.size.width = 320;
toolbar.frame = toolbarFrame;

CGRect pickerFrame = timePicker.frame;
pickerFrame.origin.y = toolbarFrame.size.height;
pickerFrame.size.width = 320;
timePicker.frame = pickerFrame;

popoverView.frame = CGRectMake(0, 0, 320, pickerFrame.origin.y + pickerFrame.size.height);

popoverContent.contentSizeForViewInPopover = popoverView.frame.size;
于 2013-08-06T07:11:40.937 回答