首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目标-c-2动画不一起工作

目标-c-2动画不一起工作
EN

Stack Overflow用户
提问于 2014-08-01 13:28:54
回答 1查看 52关注 0票数 1

我试图创建一个动画,当我在表视图中单击一个单元格时:

1)创建此单元格的克隆,并将其发送到视图的顶部;2)将我的表视图发送到左侧。

但我不能让他们一起工作。使用下面的代码,我可以将单元格的动画放在顶部,但我的表视图保持在原处(而不是向左移动):

代码语言:javascript
复制
- (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);
    }];

}

我意识到当我移除这一行时:

代码语言:javascript
复制
[self.view insertSubview:headerView aboveSubview:self.newsTableView];

表视图按我的意愿向左转,但我已经没有单元格动画了

致以问候!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-01 19:42:48

我拿到了:

代码语言:javascript
复制
- (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);
    }];
}

它工作得很好,我可以做的效果,包括另一个侧面的看法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25081374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档