我正在研究一個原型(我對目標C太綠了),它有一個隱藏或顯示tableview的按鈕。 tableview從下到上出現,當你按下該按鈕時,它將通過將其滑回底部來隱藏該tableview。該tableview是一個子視圖btw。目標C:UITableView隱藏動畫不工作
下面是這個事情,「顯示」動畫效果很好,但隱藏動畫沒有,它實際上將桌面視圖從頂部滑動到視圖中,這顯然有些事情我沒有得到正確的結果。這裏的代碼:
if(self.showLists){
self.showLists = NO;
//This is the show animation which is working properly
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[self.tableView setFrame:CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, 0-self.tableView.frame.size.height)];
[UIView commitAnimations];
}else{
self.showLists = YES;
//This is the hide animation, the one that's not working as intended
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[self.tableView setFrame:CGRectMake(0, self.tableView.frame.size.height, self.tableView.frame.size.width, 0)];
[UIView commitAnimations];
}
我敢肯定,這是完全愚蠢的,但有時最小的細節是最糟糕的。據我所知,CGRectMake的第二個參數是我希望tableview在動畫完成時的位置,0代表頂部,而tableview的高度(比如500)代表右下角?
謝謝大家!
您是否使用自動佈局設置tableview? – Istvan
是的,你認爲這是造成衝突? –