在设备方向更改期间禁用某些动画

时间:2016-02-17 10:23:10

标签: ios swift2 core-animation calayer quartz-core

有没有办法在仅在一个UIView及其子视图中更改设备方向纵向/横向时禁用旋转动画。

目前我正在使用此post中的类似内容:

override func viewWillTransitionToSize(size: CGSize,
      withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    CATransaction.begin()
    CATransaction.setDisableActions(true)

    coordinator.animateAlongsideTransition({ (ctx) -> Void in

    }, completion: { (ctx) -> Void in
      CATransaction.commit()
  })

}

但是这个解决方案会在屏幕上的每个UIView中更改方向时禁用所有动画。

我还试图创建UIView的特殊NotAnimatedView子类,但根本没有运气:

class NotAnimatedView: UIView {

  override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
    if event == "bounds" || event == "position" {
      return NSNull()
    }
    return super.actionForLayer(layer, forKey: event)
  }


}

“bounds”和“position”是在更改设备方向期间发生的两个事件,因此我覆盖它们并根据Apple Documentation返回NSNull()

但它不起作用。 NotAnimatedView也是动画。似乎我不明白某些事情,或者我对CALayer的理解是错误的。有人可以更多地谈谈这个话题吗?

0 个答案:

没有答案
相关问题