2

我已经在故事板上拖放了一个 barButtonItem 并且一直在使用这个弹出框代码,但是

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

barButtonItem.frame 不起作用,因为没有可用的 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];    
4

1 回答 1

6

我觉得可以[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];直接使用。

于 2013-07-23T04:27:18.703 回答