0

私は愚かなことに困っています:ナビゲーションバーとテーブルビューを備えたビューを持っています。私のナビゲーション バーには「検索」の左ボタンがあります。ユーザーがこの「検索」ボタンを押すと、テーブル ビューがダウンし、ナビゲーション バーとテーブル ビューの間に検索専用の新しいビューが表示されます。

  • UITextfield を実装するだけのView Controllerがあります:

    #import <UIKit/UIKit.h>
    
    
    @interface serachBox : UIViewController <UITextFieldDelegate> {
         IBOutlet UITextField *kWTextField;     
    } 
    
    @end
    
  • 私の他のView Controllerには私の要素(ナビゲーションバー、テーブルバーなど)があります。検索ボタンを押すときに使用する機能は次のとおりです。

    - (void) pressSearchBtn:(id)sender{
    
        [searchBox.view setFrame:CGRectMake(0, -100, 320, 100)];
        CGRect theFrame = self.view.frame;
        [UIView beginAnimations:@"frame" context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        theFrame.origin.y = 100;   
        [self.view addSubview:searchBox.view];
        self.view.frame = theFrame;
        [UIView commitAnimations];
    
    }
    

私の問題 : 検索ボックス ビューは正常に表示されますが、クリックしてもテキスト フィールドが応答しません。私は単純なサブビューの追加を(アニメーションを実行せずに)テストしましたが、うまくいきました。

何か問題でもありますか ?

4

3 に答える 3

0

やあ、ついに私はあなたのためにそれを成し遂げました。

インターフェイスビルダーの任意の場所にテキストフィールドを配置し、ツール->属性インスペクターで非表示にします。

あなたのviewDidLoadメソッドでこれを行います

- (void)viewDidLoad {

    CGRect frame = CGRectMake(0, -100, 320, 580);

    self.view.frame = frame;

    text.frame = CGRectMake(0, self.view.frame.origin.y, 320, 100);

    [super viewDidLoad];
}

次に、btnClick メソッドでこれを記述します。

-(IBAction) btnClicked: (id) sender
{

    CGRect frame1 = CGRectMake(0, 0, 320, 100); 
    text.hidden = FALSE;
    CGRect frame = self.view.frame;
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    frame.origin.y = 0;
    self.text.frame = frame1;
    self.view.frame = frame;
    [UIView commitAnimations];

}

乾杯!!!

于 2011-03-14T19:30:21.930 に答える
0

または、これを行うことができます。Interface Builder で、テキストフィールドをビューの外ではなく、ビューの真上に配置します。サイズ (320,31) で (0,0) に配置します。次に、tools->attributes インスペクターで、テキストフィールドの隠しプロパティを true にチェックします。次に、buttonClick にこのコードを入力します。

- (void) pressSearchBtn:(id)sender{ 

    kwtextField.alpha = 0;
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    kwtextField.hidden = FALSE;
    kwtextField.alpha = 1;
    [UIView commitAnimations];
}
于 2011-03-14T15:38:57.590 に答える
0

Hey add this in the pressSearchBtn action towards the end.

[kWTextField becomeFirstResponder];

于 2011-03-14T15:20:58.817 に答える