UIView

2011-12-10 13 views
1

キーボードを使用しているときにUIView全体を動かしているアプリケーションがあります。重要なものを隠さないためにUITextFieldを使用しています。UIView

私の問題は、私がそこに持っているUITableViewは他のすべてのビューと同じように動作しないということです。 UITableView全体を移動するのではなく、その上端のみを移動し、UITableViewのサイズを変更します。これは目的の効果ではありません。

私の問題をよりよくここで説明されていますhttp://www.youtube.com/watch?v=AVJVMiBULEQ

は、これは私がアニメーションのために使っているコードです:

-(void)setViewMovedUp:(BOOL)movedUp 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; // if you want to slide up the view 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    CGRect rect = self.view.frame; 

    if (movedUp) { 
     // 1. move the view's origin up so that the text field that will be hidden come above the keyboard 
     // 2. increase the size of the view so that the area behind the keyboard is covered up. 
     rect.origin.y -= 140; 
     rect.size.height += 140; 
    } else { 
     // revert back to the normal state. 
     rect.origin.y += 140; 
     rect.size.height -= 140; 
    } 

    self.view.frame = rect; 

    [UIView commitAnimations]; 
} 
+0

フム、私はいつも(下に移動)self.transfom = CGAffineTransformMakeTranslation(0、-140)を形質転換し、self.transform = CGAffineTransformIdentity設定することによってこれを行います。あなたはこれを試して、あなたが同じ結果を得るかどうかを見てみることができますか? –

+0

ありがとうございます。これはうまくいきましたが、アニメーションなしで即座に動きます。これにアニメーションを追加する方法はありますか? – Dimme

+0

Interface Builderで自動サイズ設定オプションを変更して解決しました。 =)サイズ変更に固執していました。 – Dimme

答えて

1

上記のコメントで解決したように、ビューが自動サイズ変更されていない場合に上記のコードは動作します。より単純なアプローチは、あなたの代わりにビューフレームを計算するCGAffineTransform変換を使用することです。

-(void)setViewMovedUp:(BOOL)movedUp { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; // if you want to slide up the view 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    if (movedUp) { 
     self.transform = CGAffineTransformMakeTranslation(0, -150);//move up for 150 px 
    } else { 
     self.transform = CGAffineTransformIdentity;//reset to initial frame 
    } 

    [UIView commitAnimations]; 
}