0

ユーザーが uitextfiel をタップすると、ビューがアニメーション化されて、キーボードがそのフィールドを非表示にしないようになりました。正常に動作しますが、その間にデバイスを回転させると正常に動作しません。

私のビューコードは以下の通りです

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
-(void)textFieldShouldReturn:(id) sender
{
[sender resignFirstResponder];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField:textField up:NO];
}
-(void)animateTextField:(UITextField*)textField up:(BOOL)up
{
const int movementDistance = -130;
const float movementDuration = 0.3f;

int movement = (up ? movementDistance : -movementDistance);

[UIView beginAnimations: @"animateTextField" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}

テキストフィールドをタップしたら、以下を確認してください

ここに画像の説明を入力

ここに画像の説明を入力

このキーボードを上げた位置で、デバイスを回転させます。以下を確認してください

ここに画像の説明を入力

キーボードのリターンをタップすると、以下を確認してください

ここに画像の説明を入力

あなたが見ることができる、問題

ありがとう

4

1 に答える 1

0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);




[textfield resign first responder];
}

関数のように使用するものは何でも追加するだけです

[textfield resign first responder];
于 2013-04-05T11:49:12.183 に答える