Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UITableView中的快速衰落单元_Uitableview_Swift_Xcode6_Fade_Tableviewcell - Fatal编程技术网

UITableView中的快速衰落单元

UITableView中的快速衰落单元,uitableview,swift,xcode6,fade,tableviewcell,Uitableview,Swift,Xcode6,Fade,Tableviewcell,我在Xcode 6上的swift中的UITableView遇到问题: 我希望我的UITableView单元格在出现/消失时淡入/淡出 我在网上找了很多淡入淡出的动画,但没有找到我想要的,因为它是基于持续时间的动画 我想我需要的是一种基于阿尔法的面具?我不是苏尔人,我甚至不知道要创造一个 我有一个UIViewController,其中包含一个tableView和UITableView上下两侧的一些空白(目前) 谢谢你的帮助 最好的 Anatole动画持续时间似乎合适,因为淡入/淡出有一个持续时间:

我在Xcode 6上的swift中的UITableView遇到问题:

我希望我的UITableView单元格在出现/消失时淡入/淡出

我在网上找了很多淡入淡出的动画,但没有找到我想要的,因为它是基于持续时间的动画

我想我需要的是一种基于阿尔法的面具?我不是苏尔人,我甚至不知道要创造一个

我有一个UIViewController,其中包含一个tableView和UITableView上下两侧的一些空白(目前)

谢谢你的帮助

最好的


Anatole

动画持续时间似乎合适,因为淡入/淡出有一个持续时间:随着时间的推移,细胞逐渐变得可见或不可见

下面是使表格单元格淡入的示例:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    cell.textLabel?.text = self.items[indexPath.row]
    cell.backgroundColor = UIColor.grayColor()
    cell.alpha = 0

    UIView.animateWithDuration(2, animations: { cell.alpha = 1 })

    return cell
}
编辑:

这将基于单元格的y位置设置单元格的alpha,y位置可能更接近您想要的位置:

func scrollViewDidScroll(scrollView: UIScrollView) {

    for cell in tableView.visibleCells() as [UITableViewCell] {

        var point = tableView.convertPoint(cell.center, toView: tableView.superview)
        cell.alpha = ((point.y * 100) / tableView.bounds.maxY) / 100
    }
}

我也在寻找同样的东西,最后我自己做了,我想我会分享它:

func scrollViewDidScroll(_ scrollView: UIScrollView) {

    let cellCount = tableView.visibleCells.count
    let alphaInterval:CGFloat = 1.0 / CGFloat(cellCount / 2)

    for (index,cell) in (tableView.visibleCells as [UITableViewCell]).enumerated() {

        if index < cellCount / 2 {
            cell.alpha = CGFloat(index) * alphaInterval
        } else {
            cell.alpha = CGFloat(cellCount - index) * (alphaInterval)
        }
    }
}
最后看起来像这样:


从未尝试过此操作,但请先尝试将“不透明度”设置为0,然后使用
tableView(\uux0:willDisplayCell:ForRowatineXpath:)
将动画设置为1。您好,Timon,非常感谢您的帮助!正如我所说,我不是在寻找一个有持续时间的动画,因为当用户滚动得很快时,所有的屏幕都会消失,而当他滚动得很慢时,动画就不够长了。如果它存在,我需要一个特定距离的动画。否则,我在想是否存在任何遮罩方法。通过在tableView的顶部和底部应用alpha渐变遮罩,它将允许淡入/淡出单元格。对不起,我知道我问了很多,但我在网上没有找到类似的东西。。。再次感谢,希望你有一个想法!最好的办法是,安纳托利在上面添加了另一种溶液,根据细胞的y位置改变α值。如果你把它扩展到只适用于屏幕的上三分之一,并将效果反转到屏幕的下三分之一,那应该会让你非常接近?谢谢蒂蒙,这太完美了!!只要我有空闲时间,我就会测试一下@丁满谢谢,但是如何用动画一个接一个地显示细胞呢?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.textLabel?.text = countries[indexPath.row].uppercased()
    cell.textLabel?.textColor = .white
    cell.backgroundColor = .clear
    cell.alpha = 0.25

    UIView.animate(withDuration: 0.5, animations: {
        cell.alpha = 1 
    })

    return cell
}