5

我正在尝试在横向方向的 ipad 中心显示 PopOver。我现在可以使用下面的代码执行此操作,但它没有与情节提要上链接的“popOverViewController”关联的属性。我希望它成为故事板上的视图,以便我能够对其进行处理和编辑。以及能够将其大小更改为 ipad 全视图的 50% 或 75% 并且没有箭头...

拜托,任何事情都会有所帮助。*更新代码....现在可以设置大小。但仍然没有看到“popOverViewController”的内容。

self.popOverViewController = [[PopOverViewController alloc]init];
self.popOver = [[UIPopoverController alloc]
                            initWithContentViewController:self.popOverViewController];
CGSize size = CGSizeMake(400.0,300.0);
[self.popOver setPopoverContentSize:size];
CGRect rect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1, 1);
[self.popOver presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];
4

5 回答 5

1

只需复制并粘贴以下代码

UIViewController *popovercontroller=[[UIViewController alloc] init];
UIView *popoverView=[[UIView alloc] initWithFrame:CGRectMake(312,390, 400, 344)];
popoverView.backgroundColor=[UIColor whiteColor];

popovercontroller.contentSizeForViewInPopover=CGSizeMake(400, 300);



UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 400, 0)];
[pickerView setTintColor:[UIColor blackColor]];
[pickerView addTarget:self action:@selector(dueDateChanged:) forControlEvents:UIControlEventValueChanged];

pickerView.datePickerMode = UIDatePickerModeDate;
pickerView.hidden = NO;
NSString *bs ; //= [NSString alloc];
//    //NSDate *newDate = [NSData alloc];
bs =  CurrentSelectedDate;
if (bs.length >= 1) {
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init] ;
    //        //[dateFormatter setDateStyle:NSDateFormatterLongStyle];
    //        [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
    [dateFormatter setDateFormat:@"dd-MMM-yyyy"];
    // NSDate *myDate = [dateFormatter dateFromString: txtText.text];
    pickerView.date = [dateFormatter dateFromString: CurrentSelectedDate];

}
else
{
    pickerView.date = [NSDate date];
}
[popoverView addSubview:pickerView];



// pickerView.date = [dateFormatter dateFromString:txtText.text];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
pickerToolbar.barStyle = UIBarStyleDefault;
pickerToolbar.barTintColor=[UIColor colorWithRed:150.0f/255.0f green:91.0f/255.0f blue:129.0f/255.0f alpha:1.0f];

[pickerToolbar sizeToFit];
self.navigationController.toolbar.barTintColor = [UIColor colorWithRed:150.0f/255.0f green:91.0f/255.0f blue:129.0f/255.0f alpha:1.0f];
NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
doneBtn.tintColor=[UIColor whiteColor];
[barItems addObject:doneBtn];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
 cancelBtn.tintColor=[UIColor whiteColor];
[barItems addObject:cancelBtn];

[pickerToolbar setItems:barItems animated:YES];


[popoverView addSubview:pickerToolbar];
popovercontroller.view=popoverView;

pickerViewPopup = [[UIPopoverController alloc] initWithContentViewController:popovercontroller];

[pickerViewPopup presentPopoverFromRect:CGRectMake(312, 212, 400, 344) inView:self.view permittedArrowDirections:0 animated:YES];
于 2014-04-02T06:48:49.273 回答
0

您看不到任何内容的原因是,通过从头开始显式重新创建您已经连接到插座的视图控制器,编译器假定您想要丢弃旧值并释放 IB 创建的视图控制器实例。或者,如果这是一个单独的故事板或 XIB,那么正确的初始化程序将是-initWithNibName:bundle:. 只需省略/编辑第一行,假设插座连接正确,您应该看到您在 IB 中放置的内容。

于 2013-03-05T21:24:19.617 回答
0

好的。所以我做了这个...

popOverViewController =  [self.storyboard instantiateViewControllerWithIdentifier:@"popOver"];
于 2013-03-06T16:21:23.063 回答
0

我一直在努力解决这个问题,但想在故事板中做尽可能多的事情,这会稍微改变方法:

1)选择情节提要中的弹出框并取消勾选向上/向下/向左/向右方向以摆脱箭头。

要将其集中在屏幕覆盖上,为 segue 做准备并执行以下操作:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
    CGFloat horizontalInset = (self.view.frame.size.width - popover.popoverController.popoverContentSize.width) / (CGFloat)2.0;
    CGFloat verticalInset = (self.view.frame.size.height - popover.popoverController.popoverContentSize.height) / (CGFloat)2.0;
    popover.popoverController.popoverLayoutMargins =
        UIEdgeInsetsMake(
            verticalInset,
          horizontalInset,
            verticalInset,
          horizontalInset);
}

在我的情况下,我还发现 popover segue 的圆角半径与我的设计不匹配,所以我将背景颜色更改为清除以对其进行排序,即将其添加到上面的块中:

popover.popoverController.backgroundColor = [UIColor clearColor];

2)在segue的目标控制器中找到属性'Popover'并勾选'Use Explicit Size'并将您希望它出现在popover模式下的大小。

于 2014-08-14T11:46:22.463 回答
0

使背景颜色清晰几乎对我有用,但它弄乱了变灰的背景。直接在箭头后面的视图部分是清晰的,而背景的其余部分是灰色的。所以我把颜色改成了灰色的alpha。

 UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:newViewController];

 popoverController.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.15];
于 2014-09-18T21:05:24.583 回答