ios - 为什么动画 block 中的 alpha 和约束常量位置不同

标签 ios swift autolayout

我正在尝试了解 iOS 中的动画

如果我想改变 View 的 heightConstraint 我设置这样的代码

@objc func handleAnimatioButtonTapped(){
  targetViewHeightConstraint.constant = 200
  UIView.animated(2) {
    self.view.layoutIfNeeded()
  }
}

我读到了关于 layoutIfNeeded()setNeedsLayout、异步和同步

但是当我想改变alpha时

为什么代码是这样的?

@objc func handleAnimatioButtonTapped(){
  UIView.animated(2) {
    self.targetView.alpha = 0
  }
}

最佳答案

您不需要调用layoutIfNeeded()或任何其他函数,因为您没有更新任何东西的布局/位置,只是更新 View 的alpha值。

关于ios - 为什么动画 block 中的 alpha 和约束常量位置不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49715452/

相关文章:

ios - 为不同设备自定义tableviewcell不同位置

ios - 使用 AutoLayout/UIScrollView 设置约束时了解 UIView 高度

ios - iOS 10-11 上的 NSLayoutConstraint 动画问题

iphone - 是否可以判断一个应用程序被打开了多少次?

ios - 从坐标创建 MKMapRect 并使用 mapView.visibleMapRect

Swift - 通过侧面菜单在它们之间切换时保留实例化的 View Controller

ios - UITapGestureRecognizer 不适用于 Google Maps SDK

iOS TableView

ios - Swift 3 - UITableView 在 UIScrollView 中被截断

ios - 如何让 Sprite 只在地面上快速跳跃?