2014-09-26 61 views
0

具有持续时间的动画我同时使用animateWithDuration块得到一个错误的方法问题在迅速

下面是我的代码:

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() 
    }) 
} 

我试过的解决方案在link

但我的问题没有解决。

下面

是截图:

enter image description here

请帮助我。

在此先感谢

回答

2

看来,问题是,如果有迅速自动返回只有一个闭合声明的事实。您可以解决此通过添加明确的回报:

UIView.animateWithDuration(0.2, 
    animations: { 
     backGrndView?.backgroundColor = UIColor.redColor() 
     return 
    }, 
    completion: { finished in 
     backGrndView?.backgroundColor=UIColor.redColor() 
     return 
}) 

本声明:

backGrndView?.backgroundColor = UIColor.redColor() 

回报()?是相同Void?,但关闭返回类型为Void