ios - 替换 Autolayout NSConstraints 设置中的 View

标签 ios

我在 Interface Builder 中只使用了 NSConstraints 来设置 View 。现在我有一个要制作动画的 StackView。这会导致所有布局错位。

  1. 我曾尝试用临时 View (具有相同的框架)替换 View (StackView),但这没有用。
  2. 我还尝试设置 translatesAutoresizingMaskIntoConstraints

  3. 还尝试了以下方法:

    self.numbers_Top_Constraint.constant = self.topscreen.frame.size.height
    self.topscreen.setNeedsUpdateConstraints()
    UIView.animate(withDuration: 0.5, animations: {
    
        self.topscreen.layoutIfNeeded()
    

你知道怎么做吗?

最佳答案

使用约束而不是更改框架。 设置堆栈 View 的顶部边距约束,然后在动画之前更改它并调用 self.view.layoutIfNeeded()。 像这样的东西 -

self.numbersStackViewTopMarginConstriant.constant = self.view.frame.size.height
UIView.animate(withDuration: 0.5, animations: {

            self.view.layoutIfNeeded()

        }) { (Bool) in

关于ios - 替换 Autolayout NSConstraints 设置中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44455598/

相关文章:

ios - Swift - 在 tableView.deleteRows 上崩溃(在 : [selectedIndexPath], 处,: . 自动)

android - iOS/Android Phonegap - 智能手机纵向,平板电脑横向

ios - 2个 View Controller 之间的Segue(模态)

ios - 优化正在加热设备的多个连续动画

ios - Swift 3 中的 JSON 解析和可选项

ios - 自定义 CAGradientLayer 不设置动画

ios - 如何在 REST api 中处理 URI?

ios - UITextView 上的 NSMutableAttributedString 不可点击

ios - socket.IO-objc 示例返回服务器代码 400

来自 Web 应用程序的 iOS 外部附件框架