卡在UIActionSheetPicker,iOS [英] Stuck with UIActionSheetPicker , iOS

查看:80
本文介绍了卡在UIActionSheetPicker,iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将是一个非常有针对性的问题,因为对于实际上使用 UIActionSheetPicker 之前.

This is going to be a very targeted question , as its for people that have actually used the UIActionSheetPicker before.

我在iphone应用程序中使用了它,并且一切正常,但是现在我尝试在ipad上实现它,我遇到了一些问题.

I used it in my iphone applications and everything worked great , but now that i tried to implement it on my ipad i experienced some problems.

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

The main problem is that on ipad the picker appears as a "bubble" or "info window" if you prefer , which points at the spot where it was called , like a button a text field etc.

下面是一个示例:

您可以看到信息窗口"指向动物按钮.

You can see that the "info window" is pointing at the animals button.

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

In my application i have 4 different buttons. 2 are in the top side of the screen and 2 at the bottom.

那些在最下方的人会很好地呼叫选择器,并且选择器会出现在指向他们的按钮上方.

Those who are at the bottom , call the picker very well and the picker appears on top of the buttons pointing down on them.

但是,当他们调用选择器时,屏幕顶部的那些(几乎与图像中的那个相似)选择器在屏幕上显得很低,并且没有指向它们应有的位置...

However , the ones on the top of the screen (almost like the one in the image) when they call the picker the picker appears much lower on the screen and doesnt point at them as it should ...

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

I mean i expected to appear just under the buttons pointing at them (like in the image), but they are almost in the center of the screen pointing nowhere..

有什么想法吗?有人曾经经历过吗?

Any ideas? Has someone experienced this before?

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

In the beginning , i was calling the ActionSheetPicker inside the buttons action like this:

- (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 = @"";

}

现在我正试图这样称呼它:

Now i am trying to call it like this:

- (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.

Where topicField is my TextField.

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

Sadly the result is the same. Even now that i am specifying where i want the arrow to point , the picker is called 300 pixels down.

奇怪的是,即使使用另一个比前一个按钮低一点的按钮,拾取器又精确地下降了300像素.

The strange thing is though that even with another other button that is a bit lower than the previous the picker is again exactly 300 pixels down.

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

After noticing that the picker shows 300 pixels down , i decided to manually make it show 300pixels up , to point exactly on my button.

我使用了以下代码:

- (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像素的相同位置.我开始相信,这可能不是改变选取器位置的属性.

Amazingly the button once again appears in the same position 300pixels down. I start to believe that this one may not be the property to alter the position of the picker.

有什么想法吗?

推荐答案

在调用代码中设置presentFromRect不会有所不同,因为它将根据ActionSheetPicker代码中的sender进行重置,而您将需要修改库的源代码.

Setting the presentFromRect in your calling code won't make a difference since it will be reset based on the sender within the ActionSheetPicker code, instead you are going to need to modify the source code of the library.

在github上进行以下(未合并)提交可以解决问题在iPad上,将弹出窗口设置为指向正确放置在其容器中.

The following (unmerged) commit on github should resolve the issue On iPad, set the popover to point properly at its container.

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

Basically within the AbstractActionSheetPicker.m file modify the - (void)presentPickerForView:(UIView *)aView method like the following

- (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];
    }
}

这篇关于卡在UIActionSheetPicker,iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆