Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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
Ios 在swift中使用持续时间设置动画的问题_Ios_Swift_Animation - Fatal编程技术网

Ios 在swift中使用持续时间设置动画的问题

Ios 在swift中使用持续时间设置动画的问题,ios,swift,animation,Ios,Swift,Animation,在animateWithDuration:animations:completion:method中使用块时出错 下面是我的代码: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { var cell=tableView.cellForRowAtIndexPath(indexPath) var backGrndView:UIView?=cell?.cont

在animateWithDuration:animations:completion:method中使用块时出错

下面是我的代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var cell=tableView.cellForRowAtIndexPath(indexPath)
    var backGrndView:UIView?=cell?.contentView.viewWithTag(2) as UIView?
    UIView.animateWithDuration(0.2,
        animations: {
            backGrndView?.backgroundColor=UIColor.redColor()
        },
        completion: { finished in
            backGrndView?.backgroundColor=UIColor.redColor()
    })
}
我尝试了一下解决方案

但是我的问题没有解决

以下是截图:

请帮帮我


提前感谢

问题似乎在于,如果闭包中只有一条语句,swift auto就会返回。您可以通过添加显式返回来解决此问题:

UIView.animate(withDuration: 0.2,
                           animations: {
                            backGrndView?.backgroundColor = UIColor.red
                            return
},
                           completion: { finished in
                            backGrndView?.backgroundColor = UIColor.red
                            return
})
本声明:

 backGrndView?.backgroundColor = UIColor.red

返回的
()?
Void?
相同,但闭包返回类型是
Void

,似乎问题在于,如果闭包中只有一条语句,swift会自动返回。您可以通过添加显式返回来解决此问题:

UIView.animate(withDuration: 0.2,
                           animations: {
                            backGrndView?.backgroundColor = UIColor.red
                            return
},
                           completion: { finished in
                            backGrndView?.backgroundColor = UIColor.red
                            return
})
本声明:

 backGrndView?.backgroundColor = UIColor.red

返回的
()?
Void?
相同,但闭包返回类型是
Void

,似乎问题在于,如果闭包中只有一条语句,swift会自动返回。您可以通过添加显式返回来解决此问题:

UIView.animate(withDuration: 0.2,
                           animations: {
                            backGrndView?.backgroundColor = UIColor.red
                            return
},
                           completion: { finished in
                            backGrndView?.backgroundColor = UIColor.red
                            return
})
本声明:

 backGrndView?.backgroundColor = UIColor.red

返回的
()?
Void?
相同,但闭包返回类型是
Void

,似乎问题在于,如果闭包中只有一条语句,swift会自动返回。您可以通过添加显式返回来解决此问题:

UIView.animate(withDuration: 0.2,
                           animations: {
                            backGrndView?.backgroundColor = UIColor.red
                            return
},
                           completion: { finished in
                            backGrndView?.backgroundColor = UIColor.red
                            return
})
本声明:

 backGrndView?.backgroundColor = UIColor.red

返回
()?
这与
Void?
相同,但闭包返回类型是
Void

你在使用swift 3吗?@Cruz,我想我是。你在使用swift 3吗?@Cruz,我想我是。你在使用swift 3吗?@Cruz,我想我是。