我正在尝试创建一个动画,当我从表格视图中单击一个单元格时:
1)我创建了这个单元格的克隆并将其发送到我的视图顶部; 2)将我的tableview发送到左侧
但我不能让他们一起工作。使用下面的代码,我将单元格的动画放到顶部但我的tableview保持原样(不向左移动):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//cloning UITableViewCell view for later work
NSData *tempArchiveView = [NSKeyedArchiver archivedDataWithRootObject:[tableView cellForRowAtIndexPath:indexPath]];
UIView *headerView = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveView];
headerView.frame = CGRectMake(0,
headerView.frame.origin.y,
headerView.frame.size.width,
headerView.frame.size.height);
//adding to the main view
[self.view insertSubview:headerView aboveSubview:self.newsTableView];
[UIView animateWithDuration:0.5 animations:^{
//move my tableview to the left
self.newsTableView.center = CGPointMake(-300, tableView.center.y);
//send my header to the top starting from
headerView.frame = CGRectMake(0, 0, headerView.frame.size.width, headerView.frame.size.height);
}];
}
我意识到当我删除这一行时:
[self.view insertSubview:headerView aboveSubview:self.newsTableView];
表格视图按我的要求向左移动,但我不再有单元格动画
问候!
答案 0 :(得分:0)
我明白了:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//clone tableview cell for later work
NSData *tempArchiveView = [NSKeyedArchiver archivedDataWithRootObject:[tableView cellForRowAtIndexPath:indexPath]];
self.headerView = [NSKeyedUnarchiver unarchiveObjectWithData:tempArchiveView];
//save te frame in relation to tableview's supervir
CGRect cellPositionOnWindow = [tableView rectForRowAtIndexPath:indexPath];
CGRect rectInSuperview = [tableView convertRect:cellPositionOnWindow toView:[tableView superview]];
apply this frame to the clone
self.headerView.frame = rectInSuperview;
[self.view addSubview:self.headerView];
[UIView animateWithDuration:0.5 animations:^{
//I decided to move the bounds instead of the frame
self.view.bounds = CGRectMake(320,
self.view.frame.origin.y,
tableView.frame.size.width,
tableView.frame.size.height);
self.headerView.frame = CGRectMake(320,
0,
self.headerView.frame.size.width,
self.headerView.frame.size.height);
}];
}
它工作得很好,我可以做到包括另一个横向视图的效果。