【问题标题】:UIView animation is clouding UICollectionView delegate - SwiftUIView 动画使 UICollectionView 委托蒙上阴影 - Swift
【发布时间】:2016-07-26 20:53:35
【问题描述】:

UIView.animateWithDuration 和 UICollectionView Delegate 之间是否存在任何已知的故障?

如果我对用作 UIViewController 背景的 UIImageView 进行动画处理,我的 UICollectionViewCell 无法点击(根本不调用 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

    ...
}

【问题讨论】:

    标签: ios iphone swift delegates uicollectionview


    【解决方案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()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      相关资源
      最近更新 更多