0

私は a を持っています-- aと aを含むUIViewそれを呼び出します。つまり、サブビューです。これらはforに追加されます。百聞は一見に如かず。HomeViewUITableViewUISearchBarviewDidLoadHomeView

ここに画像の説明を入力

ここに画像の説明を入力

これらのスクリーンショットからわかるようにUITableView、 が表示されると、 の最初の項目が非UISearchBar表示になります。関連するコードは次のとおりです。

- (void) viewDidLoad
  self.table_view = [UITableView.alloc.initWithFrame: self.view.bounds style:UITableViewStylePlain];
  self.table_view.bounds.origin.y += 44;
  self.table_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  // ^^^ This is the code I believe is one source of my problem



// Triggered when search button in nav bar is pressed

// code to calculate delta here

// Here's how the view is animated. The search bar frame
// is dropped down (works), and ideally, the tableview
// drops down exactly the same amount at the same time.
// If the action is to hide, then the inverse happens
// because +delta+ will have been calculated as a
// negative number above.
[UIView animateWithDuration: 0.7
  delay: 0.0
  options: UIViewAnimationOptionCurveEaseIn
  animations:^ {
    self.searchBar.frame = CGRectOffset(@searchBar.frame, 0.0, delta);
  }
  completion:^(BOOL finished){
    self.searchBarVisible = !self.searchBarVisible
    self.searchBar.hidden = !self.searchBarVisible
    edgeInsets = UIEdgeInsetsMake(0.0f, self.searchBarVisible ? delta : 0.0f, 0.0f, 0.0f)
    [tableView setContentInset: edgeInsets]
  }
];

実際に何が起こるかというと、検索ボタンを押すと検索バーが期待どおりに下にスライドし、次にボタンを押すと上にスライドします。ただし、テーブル ビューは調整されません。

私が知る限りの問題はviewDidLoad、 では囲みHomeViewがレンダリングされていないため、サイズがまだ不明であることです。画面のサイズを取得してそれを使用することはできますが、自動サイズ変更マスクの方が優れていると思いましたよね?

これには明らかな欠陥がありますか?検索バーと同時にテーブルビューをアニメーション化する方法はありますか?

ありがとう

4

1 に答える 1

0

よし、これをもう一度やってみよう!

アニメーションブロックで、edgeInsetsを作成する行を次のように変更します。

edgeInsets = UIEdgeInsetsMake(self.searchBarVisible ? delta : 0.0f, 0.0f, 0.0f, 0.0f);

私の知る限り、最初の引数は上で、設定したものは左の挿入図でした。

于 2012-06-19T18:46:29.997 に答える