相关疑难解决方法(0)

手风琴表格单元格 - 如何动态扩展/收缩uitableviewcell?

我正在尝试创建一个手风琴类型的uitableviewcell,当用户选择单元格时,它会展开以显示内嵌的详细信息视图,类似于digg应用程序的工作方式.我最初尝试用cellForRowAtIndex中的customcell替换当前的tablecell但是动画看起来有点不稳定,因为你可以看到被替换的单元格,整体效果不好.

如果你看看digg应用程序以及其他已经完成此操作的应用程序,似乎它们不会替换当前的单元格,而是可能在单元格中添加子视图?然而,原始单元似乎根本没有动画,只有新视图符合表格.

有没有人有任何想法如何实现类似的效果?

更新: 我已经使用下面的neha方法取得了一些进展,同时单元格正在动画正确的方式,它会对表格中的其他单元格造成严重破坏.我所做的是使用自定义类子类化UITableViewCell,该类包含一个实际绘制视图的UIView实例,然后我将其添加到表格单元内容视图中.

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

if (selected) { 
    [self expandCell];
}
}

-(void)expandCell { 
    self.contentView.frame = CGRectMake(0.0, 0.0, self.contentView.bounds.size.width, 110);
}
Run Code Online (Sandbox Code Playgroud)

以下是我正在使用的所有表委托方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

if (isSearching && indexPath.row == selectedIndex) {

    static NSString *CellIdentifier = @"SearchCell";
    CustomTableCell *cell = (CustomTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    [cell setCustomTitle:[timeZoneNames objectAtIndex:indexPath.row] detail:[timeZoneNames objectAtIndex:indexPath.row]];

    UILabel *theText = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 10.0, cell.contentView.bounds.size.width -20, 22.0)];
    theText.text = …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

60
推荐指数
3
解决办法
4万
查看次数

Swift 动画 UITableViewCell 扩展高度约束

我有一个带有静态单元格的 TableView,当按下按钮时,我想在其中展开。单元格内有一个容器视图,已正确设置约束,但我不确定如何实际为单元格扩展设置动画,因为它需要我刷新表视图以更新约束并扩展单元格。

目前,当我调用expandContainerView它时没有动画,因为我正在调用self.tableView.reloadData.

这是我用来扩展单元格的代码

@objc private func expandContainerView(notification: NSNotification) {

    self.view.layoutIfNeeded()

    UIView.animate(withDuration: 2.0, delay: 0.0, options: .curveEaseOut, animations: {
        self.containerHeightConstraint.constant = 410
        self.view.layoutIfNeeded()
        self.tableView.reloadData()
    }, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

这是我在索引代码处每行的高度

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    return UITableViewAutomaticDimension
}
Run Code Online (Sandbox Code Playgroud)

animation constraints tableview ios swift

5
推荐指数
2
解决办法
7491
查看次数

标签 统计

animation ×1

constraints ×1

ios ×1

iphone ×1

objective-c ×1

swift ×1

tableview ×1