gpt4 book ai didi

iphone - UIPopover 无法从 UIButton 正确显示

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:25 24 4
gpt4 key购买 nike

我有一个 UIButton,单击它时会显示一个带有 UIDatePicker 的 UIPopover。

它应该显示在出生日期按钮下方,但它却覆盖了它。

这是我的代码:

- (IBAction)dateOfBirthButtonPressed:(id)sender{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor blackColor];

UIDatePicker *datePickerTemp = [[UIDatePicker alloc]init];
datePickerTemp.frame=CGRectMake(0,44,320, 216);
datePickerTemp.datePickerMode = UIDatePickerModeDate;
datePickerTemp.maximumDate = [NSDate date];
self.datePicker = datePickerTemp;
[popoverView addSubview:self.datePicker];

UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame=CGRectMake(0,0 ,320, 40);
toolbar.barStyle = UIBarStyleBlackOpaque;
NSMutableArray *toolbarItems = [NSMutableArray array];
UIBarButtonItem *cancelButton1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(datePickerCancelButtonClicked)];
UIBarButtonItem *doneButton1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(datePickerSaveButtonClicked)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolbarItems addObject:cancelButton1];
[toolbarItems addObject:space];
[toolbarItems addObject:doneButton1];
toolbar.items = toolbarItems;
[popoverView addSubview:toolbar];
[cancelButton1 release];
[space release];
[toolbar release];

popoverContent.view = popoverView;
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
self.datePopoverController = popoverController;
[popoverContent release];
[popoverView release];

[self.datePopoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[self.datePopoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

框架的 NSLog:

DOB button: {{160, 129}, {329, 37}}
Last name label: {{160, 77}, {329, 31}}

enter image description here

最佳答案

您的按钮是 View 的 subview ,还是埋在另一个 subview 中?如果它不是您 View 的直接 subview ,那么您的坐标空间将关闭。尝试将您的代码更改为:

CGRect buttonRect = [self.dateOfBirthButton convertRect:self.dateOfBirthButton.frame toView:self.view];
[self.datePopoverController presentPopoverFromRect:buttonRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

关于iphone - UIPopover 无法从 UIButton 正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8548179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com