UIView.animateWithDuration 和 UICollectionView Delegate 之间是否存在任何已知的缺陷?
我遇到一个问题,如果我对用作 UIViewController 背景的 UIImageView 进行动画处理,则我的 UICollectionViewCells 不可点击(根本不调用 shouldSelectItemAtIndexPath
等委托(delegate)方法)
但是,如果我注释掉对动画背景的方法调用,则单元格可单击,调用委托(delegate)方法,并且一切正常。
顺便提一下,我有一个自定义 UIView 类和 Nib ,我将其加载到我的 ViewController 上(UICollectionView 位于此 View 内)。
这是我的代码:
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
...
}
最佳答案
在执行动画时,默认情况下,元素是不可交互的。您可以通过发送 .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()
}
}
关于ios - UIView 动画使 UICollectionView 委托(delegate)变得模糊 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36451374/