1

这将是一个非常有针对性的问题,因为它适用于以前实际使用过UIActionSheetPicker的人。

我在我的 iphone 应用程序中使用了它,一切都很好,但是现在我尝试在我的 ipad 上实现它,我遇到了一些问题。

主要问题是,在 ipad 上,如果您愿意,选择器会显示为“气泡”或“信息窗口”,它指向调用它的位置,如按钮、文本字段等。

下面是一个例子:

在此处输入图像描述

您可以看到“信息窗口”指向动物按钮。

在我的应用程序中,我有 4 个不同的按钮。2 个位于屏幕顶部,2 个位于屏幕底部。

那些在底部的人,很好地调用了选择器,选择器出现在指向他们的按钮的顶部。

但是,屏幕顶部的那些(几乎就像图像中的那个)当他们调用选择器时,选择器在屏幕上显示得更低,并且不应该指向它们......

我的意思是我希望出现在指向它们的按钮下方(如图所示),但它们几乎位于屏幕中央,无处可去。

有任何想法吗?以前有人经历过吗?

编辑


一开始,我在按钮操作中调用 ActionSheetPicker,如下所示:

- (IBAction)selectTopic:(UIControl *)sender {
[ActionSheetStringPicker showPickerWithTitle:NSLocalizedString(@"CHOOSE_TOPIC", nil) rows:self.topics initialSelection:self.selectedIndex target:self successAction:@selector(topicWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];


//when user picks a new topic we clean the titleField to make sure selected title of previous topic doesnt mix up with new topic
        titleField.text = @"";

}

现在我试图这样称呼它:

- (IBAction)selectTopic:(UIControl *)sender {
    ActionSheetStringPicker *thePicker = [[ActionSheetStringPicker alloc] initWithTitle:NSLocalizedString(@"CHOOSE_TOPIC", nil) rows:self.topics initialSelection:self.selectedIndex target:self successAction:@selector(topicWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];

    thePicker.presentFromRect = topicField.frame;

    [thePicker showActionSheetPicker];

    //when user picks a new topic we clean the titleField to make sure selected title of previous topic doesnt mix up with new topic
titleField.text = @"";
}

topicField 是我的 TextField。

可悲的是结果是一样的。即使现在我正在指定我希望箭头指向的位置,选择器也被称为向下 300 像素。

奇怪的是,即使有另一个比前一个低一点的按钮,选择器又正好下降了 300 像素。

编辑2


在注意到选择器向下显示 300 像素后,我决定手动使其显示向上 300 像素,以准确指向我的按钮。

我使用了以下代码:

- (IBAction)selectTopic:(UIControl *)sender {
    //[ActionSheetStringPicker showPickerWithTitle:NSLocalizedString(@"CHOOSE_TOPIC", nil) rows:self.topics initialSelection:self.selectedIndex target:self successAction:@selector(topicWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];

    ActionSheetStringPicker *thePicker = [[ActionSheetStringPicker alloc] initWithTitle:NSLocalizedString(@"CHOOSE_TOPIC", nil) rows:self.topics initialSelection:self.selectedIndex target:self successAction:@selector(topicWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];


    CGRect pickerFrame = topicField.frame;
    pickerFrame.size.height -= 300;
    thePicker.presentFromRect = pickerFrame;

    [thePicker showActionSheetPicker];

    //when user picks a new topic we clean the titleField to make sure selected title of previous topic doesnt mix up with new topic
    titleField.text = @"";

}

令人惊讶的是,按钮再次出现在向下 300 像素的相同位置。我开始相信这可能不是改变选择器位置的属性。

有任何想法吗 ?

4

2 回答 2

1

在调用代码中设置 presentFromRect 不会产生任何影响,因为它将根据senderActionSheetPicker 代码中的内容进行重置,相反,您需要修改库的源代码。

github 上的以下(未合并)提交应该可以解决问题在 iPad 上,将弹出框设置为正确指向其容器。

基本上在AbstractActionSheetPicker.m文件中修改- (void)presentPickerForView:(UIView *)aView方法如下

- (void)presentPickerForView:(UIView *)aView {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
     self.presentFromRect = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
        [self configureAndPresentPopoverForView:aView];
    }
    else {
         self.presentFromRect = aView.frame;
        [self configureAndPresentActionSheetForView:aView];
    }
}
于 2013-07-03T19:52:32.817 回答
0

简要看一下代码后,我想说您要确保 ActionPicker 对象上的 presentFromRect 位于您在 init 中传入的容器的坐标中。例如,如果我有一个包含按钮的大视图:

这是未经测试的:

UIView* someBigView = ... // get the big view
UIButton* someButton = ... // get the button that the big view contains

ActionSheetDatePicker* thePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Some Title" 
    datePickerMode:UIDatePickerModeDate 
    selectedDate:[NSDate date] 
    target:self 
    action:@selector(someMethod:) 
    origin:someBigView];

//the arrow should be pointing at the button
thePicker.presentFromRect = someButton.frame;

[thePicker showActionSheetPicker];

在我看来,这个库有一个相当大的缺陷,因为它需要一个可以是按钮项或容器的 origin 参数。它要求您查看源代码以理解它,而不是从界面中(有些)明显。

于 2013-02-27T19:17:17.367 回答