ios - UIView 动画使 UICollectionView 委托(delegate)变得模糊 - Swift

标签 ios iphone swift delegates uicollectionview

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/

相关文章:

ios - 使用 ABPersonViewControllerDelegate 时的 EXC_BAD_ACCESS

android - 谷歌距离矩阵网络服务限制

ios - 将本地包中的图像发布到 Pinterest iphone。

iphone - 加载 Facebook 好友到 UITableView

swift 4 : Unable to parse JSON response

ios - Swift 变量约束

ios - Xamarin Studio iOS UI Designer 没有 Storyboard?

ios - 仅当隐藏文本字段时才使用键盘移动 View

ios - 如何在每次敲击键盘后获取文本字段的文本(Swift iOS)

ios - 我如何在 XCode 4 (iOS) 中使用 EXCLUDED_SOURCE_FILE_NAMES