UIView.animateWithDuration和UICollectionView Delegate之间是否存在任何已知的异常?
我遇到的问题是,如果我动画UIImageView作为我的UIViewController的背景,我的UICollectionViewCells不可点击(shouldSelectItemAtIndexPath
之类的委托方法根本不被调用)
但是如果我注释掉方法调用动画背景,单元格是可点击的,委托方法被调用,一切正常。
提一下,我有一个自定义的UIView类和nib,我加载到我的ViewController上(UICollectionView在这个视图中)。
这是我的代码:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
customView = NSBundle.mainBundle().loadNibNamed("customView", owner: self, options: nil)[0] as! CustomView
customView.frame = childView.bounds
self.childView.addSubview(customView)
customView.initialize()
//self.rotateView()
}
func rotateView() {
UIView.animateWithDuration(18, delay: 0, options: .CurveLinear, animations: { () -> Void in
self.backgroundImage1.transform = CGAffineTransformRotate(self.backgroundImage1.transform, CGFloat(M_PI_2))
}) { (finished) -> Void in
self.rotateView()
}
}
这是自定义UIView的initialize()方法:
func initialize(){
collectionView.backgroundColor = UIColor.clearColor()
collectionView.registerNib(cellNib, forCellWithReuseIdentifier: "Cell")
self.collectionView.delegate = self
self.collectionView.dataSource = self
...
}
答案 0 :(得分:1)
在执行动画时,默认情况下,元素是不可交互的。您可以通过发送.AllowUserInteraction
作为选项的一部分来启用它。
试试这个:
func rotateView() {
UIView.animateWithDuration(18, delay: 0, options: [.CurveLinear,.AllowUserInteration], animations: { () -> Void in
self.backgroundImage1.transform = CGAffineTransformRotate(self.backgroundImage1.transform, CGFloat(M_PI_2))
}) { (finished) -> Void in
self.rotateView()
}
}