一連のフィルターを適用している UITableView があります。「フィルター」ボタンをタップすると、ナビゲーションバーの下からフィルターがアニメーション化されます。ここで行っているのは、読み込んだNIBをUITableViewのスーパービューに追加することです。ビューを起動すると、これは完全に機能します。フィルター NIB を表示および非表示にすることができます。ただし、ホームボタンを押してアプリをバックグラウンドに送信した後、アプリを再度起動してフォアグラウンドに移動します。これで、ロードして UITableView のスーパービューにアタッチした NIB が画面を引き継ぎました。テーブルビューはこのビューの下に隠されています。フィルタ NIB を非表示にすることで、ヒットの小さなセクションを確認できます。スーパービューに追加した NIB の高さは 75 ですが、最前面に表示すると、フレームのサイズが 400 を超えていることがわかります。なぜこれがスーパービューで起こっているのかについて、誰かが何か考えを持っていますか? ありがとう
マイコード
- (IBAction)filterButtonPressed:(UIBarButtonItem *)sender
{
//If the filter view is displayed on screen then remove it.
if(self.filterViewDisplayed == YES){
[self animateFilterButtonsWithButtonsYOrigin:-75 tableViewYOrigin:-75];
self.filterViewDisplayed = NO;
}else {
//Determine if we should load the FilterButtons XIB
if(self.filterViewLoaded == NO) {
self.filterViewLoaded = YES;
[self.tableView.superview addSubview:self.activityFilter];
}
self.filterViewDisplayed = YES;
//Set the delegate of the ActivityFilter to self so that we can handle callbacks.
self.activityFilter.delegate = self;
//Set the intial frame of the filter buttons to be -75 pixels off the top of the screen
CGRect filterFrame = self.activityFilter.frame;
filterFrame.origin.y = -75;
self.activityFilter.frame = filterFrame;
//Now animate the filter buttons to appear at origin 0.
[self animateFilterButtonsWithButtonsYOrigin:0 tableViewYOrigin:75];
}
}
- (void)animateFilterButtonsWithButtonsYOrigin:(CGFloat)yOrigin tableViewYOrigin:(CGFloat)tableViewYOrigin
{
[UIView animateWithDuration:0.25
animations:^{
CGRect filterFrame = self.activityFilter.frame;
filterFrame.origin.y = yOrigin;
self.activityFilter.frame = filterFrame;
[self adjustTableViewOriginBy:tableViewYOrigin];
}];
}
-(void)adjustTableViewOriginBy:(CGFloat)yOrigin
{
CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y += yOrigin;
self.tableView.frame = tableFrame;
}
スクリーンショット
- フィルターアニメーション前
- フィルター適用後
- バックグラウンドから起動した後 - ここに問題があります。Superview はビュー全体を占有します
- フィルターを非表示にすると、スーパービューの下にテーブルビューが表示されます