我试图创建一个动画,当我在表视图中单击一个单元格时:
1)创建此单元格的克隆,并将其发送到视图的顶部;2)将我的表视图发送到左侧。
但我不能让他们一起工作。使用下面的代码,我可以将单元格的动画放在顶部,但我的表视图保持在原处(而不是向左移动):
- (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];表视图按我的意愿向左转,但我已经没有单元格动画了
致以问候!
发布于 2014-08-01 19:42:48
我拿到了:
- (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);
}];
}它工作得很好,我可以做的效果,包括另一个侧面的看法。
https://stackoverflow.com/questions/25081374
复制相似问题