0

私のiPadアプリケーションでは、フォームシートスタイルを使用してコントローラーを提示しています

controller.modalPresentationStyle=UIModalPresentationFormSheet;

横向きモードでは、デバイスのキーボードが開いている間、ユーザーがテーブルのすべてのレコードを表示できるように、tableView のサイズを設定します。

キーボードの表示/非表示のイベントを取得します。設定しましたNSNotification

問題

しかし、ユーザーが外部/仮想キーボードを使用してテーブル セルの textField をタップすると、キーボードの表示/非表示のイベントが発生しません。したがって、textfield がファーストレスポンダになると、Tableview のサイズは小さくなりますが、ユーザーが外部キーボードに接続している間は必要ありません。

誰でもここでガイド/ヘルプをお願いできますか?どうすればよいですか? 外付けキーボードを使用するときに設定サイズを停止できるようにします。

キーボード イベントの登録

- (void)registerForKeyboardNotifications{

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasHidden:)
                                             name:UIKeyboardDidHideNotification object:nil];

}

AutoRotate とテキスト フィールドがファーストレスポンダになるときにフレームを設定する

-(void)setFramesOfTable
{

CGRect rct=tableView.frame;
if(appDel.isThisIPad && ([[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationLandscapeRight) && [selectedField isFirstResponder])
{
    rct.size.height=400.0;
}
else
{
    rct.size.height=576.0;
}
tableView.frame=rct;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{

selectedField = textField;
[self setFramesOfTable];
}

-(NSUInteger)supportedInterfaceOrientations
{
[self setFramesOfTable];
return UIInterfaceOrientationMaskAll;
}

ありがとう。

4

1 に答える 1

1

テキスト フィールドの編集を開始するときにテーブルのフレームを変更するのは得策ではありません。iPad では、ユーザーは外付けキーボード、ドッキング キーボード、または分割キーボードを使用できます。

ユーザーが外部キーボードを使用している場合、ウィンドウのサイズを変更する必要はありません。外付けキーボードを使用している場合、オンスクリーン キーボードは表示されないため、ウィンドウのサイズを変更する必要はありません。

ユーザーが分割キーボードを使用している場合、ウィンドウのサイズ変更について心配する必要はありません。キーボードを分割すると、キーボードが UI の中央に配置され、分割されたキーボードの少なくとも一部で覆われないように UI を再配置することが不可能 (または少なくとも非現実的) になる可能性があります。ユーザーがキーボードを分割して重要な UI コンポーネントを隠している場合は、キーボードを邪魔にならないように移動する必要があります。

UI のサイズを変更する最良の方法は、キーボードで ChangeFrame/Hide メソッドを使用することです

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

これらのイベントのハンドラー内で、キーボードの高さを取得し、それに応じて UI を調整できます

-(void)keyboardWillChangeFrame:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    NSValue* kbFrame = info[UIKeyboardFrameEndUserInfoKey];
    NSTimeInterval animationDuration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect keyboardFrame = [kbFrame CGRectValue];
    BOOL isPortrait = UIDeviceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);
    CGFloat height = isPortrait ? keyboardFrame.size.height : keyboardFrame.size.width;
}

これにより、animationDuration とキーボードの高さが得られるため、UIView animateWithDuration ブロックを使用して、フレームの変更をテーブルビューにアニメーション化し、キーボードによって隠されないようにすることができます。

keyboardWillHide: NSNotification から animationDuration (上記と同じ方法) を取得するだけで済みます (高さは明らかに 0 になります)。次に、別の UIView animateWithDuration ブロックを使用して、元のサイズにサイズ変更されたテーブルビューをアニメーション化します

于 2013-09-11T16:52:47.310 に答える