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ピクセル下になります。

EDIT2


ピッカーが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

sender呼び出しコードで presentFromRect を設定しても、ActionSheetPicker コード内に基づいてリセットされるため、違いはありません。代わりに、ライブラリのソース コードを変更する必要があります。

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 で渡すコンテナーの座標にあることを確認する必要があると言えます。たとえば、ボタンを含む 1 つの大きなビューがあるとします。

これはテストされていません:

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 に答える