首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewCell animateWithDuration不工作

UITableViewCell animateWithDuration不工作
EN

Stack Overflow用户
提问于 2014-12-12 16:12:37
回答 1查看 1K关注 0票数 0

我的自定义单元格上有图像视图。单元格上的所有元素都有约束。我已经实现了这个方法来动画我的箭头。旋转工作良好,但没有动画。我有调试单元,并调用了nib方法。

我有从故事板单元格构建的标题:

视图控制器回调:

代码语言:javascript
复制
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *cellIdentifier = @"SectionHeader";

    KNCategorySectionCell *sectionView = (KNCategorySectionCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    sectionView.index = section;
    sectionView.delegate = self;

    KNCategoryPoxy *category = [_categories objectAtIndex:section];

    [sectionView setupViewWithState:category.state];

    sectionView.categoryName.text = category.dictionary[@"name"];

    return sectionView;
}

方法的自定义单元实现:

代码语言:javascript
复制
- (void)setupViewWithState:(KNCategoryState)state
    {
        switch (state)
        {
            case KNCategoryStateStateCollapsed:
            {
                [self.contentView setBackgroundColor:[UIColor red:255 green:255 blue:255]];

            } break;

            case KNCategoryStateStateExpanded:
            {
                [UIView animateWithDuration:10.0f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
                    self.arrowImage.transform = CGAffineTransformMakeRotation(M_PI_2);
                } completion:^(BOOL finished) {

                }];

                [self.contentView setBackgroundColor:[UIColor red:230 green:230 blue:230]];

            } break;
        }
    }

正如我所说的,旋转是工作的,但它立即旋转视图,以适当的M_PI_2,似乎没有动画。

我使用了Xcode 6.1和iOS 8.1模拟器进行测试。

另外,我在自定义单元格中实现了单个点击手势,并实现了以下方法:

代码语言:javascript
复制
- (void)singleTap
{
    [self.delegate sectionDidTappedWithIndex:self.index];
}

delegate,它是我的视图控制器,它包含显示所有自定义单元格的表。

在视图控制器中,我实现了设置头、展开和重新加载数据的方法:

代码语言:javascript
复制
- (void)sectionDidTappedWithIndex:(NSInteger)index
{
        for (KNCategoryPoxy *category in _categories)
        {
            category.state = KNCategoryStateStateCollapsed;
        }

        KNCategoryPoxy *category = [_categories objectAtIndex:index];

        category.state = !category.state;

        [self.theTableView reloadData];
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-06 11:18:14

尝试使用UIView.commmitAnimations()执行动画,例如:

代码语言:javascript
复制
 UIView.beginAnimations(“rotation”, context: nil)

    UIView.setAnimationDuration(0.8)

    cell.layer.transform = CATransform3DIdentity

    cell.alpha = 1

    cell.layer.shadowOffset = CGSize(width: CGFloat(0), height: CGFloat(0))

    UIView.commitAnimations()

还尝试在willDisplayCell:方法中执行操作。

请参考此http://www.thinkandbuild.it/animating-uitableview-cells/解决方案在tableview单元格中执行动画。

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

https://stackoverflow.com/questions/27447635

复制
相关文章

相似问题

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