我已经在Story Board上拖了一个barButtonItem并且一直在使用这个popover代码但是
[popoverController presentPopoverFromRect:self.barButonItem.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
barButtonItem.frame不起作用,因为没有可用的帧属性。
让它完美运作的最佳选择是什么? 提前致谢。
目前我正在使用此代码:我正在使用此方法:
- (IBAction)buttonClicked:(UIBarButtonItem *)sender event:(UIEvent *)event
{
UIView *viewt = [[UIView alloc] init];
for(UITouch* touch in [event allTouches] )
{
if( [touch phase] == UITouchPhaseEnded )
{
viewt = [touch view];
}
}
}
self.barButtonItem.frame
将成为viewt.frame
。
它现在正在工作。这是对的吗?
//create a popover controller with my DatePickerViewController in it
UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
UIView *popoverView = [[UIView alloc] init]; //view
popoverView.backgroundColor = [UIColor blackColor];
datePicker=[[UIDatePicker alloc]init];//Date picker
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker setMinuteInterval:5];
[datePicker setTag:10];
[datePicker addTarget:self action:@selector(Result) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:self.barButtonItem.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
答案 0 :(得分:6)
我认为您可以直接使用[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
。