• <bdo id='05GxX'></bdo><ul id='05GxX'></ul>
  • <small id='05GxX'></small><noframes id='05GxX'>

    <legend id='05GxX'><style id='05GxX'><dir id='05GxX'><q id='05GxX'></q></dir></style></legend>

      <i id='05GxX'><tr id='05GxX'><dt id='05GxX'><q id='05GxX'><span id='05GxX'><b id='05GxX'><form id='05GxX'><ins id='05GxX'></ins><ul id='05GxX'></ul><sub id='05GxX'></sub></form><legend id='05GxX'></legend><bdo id='05GxX'><pre id='05GxX'><center id='05GxX'></center></pre></bdo></b><th id='05GxX'></th></span></q></dt></tr></i><div id='05GxX'><tfoot id='05GxX'></tfoot><dl id='05GxX'><fieldset id='05GxX'></fieldset></dl></div>

        <tfoot id='05GxX'></tfoot>

        约束不随设备方向更改而更新

        Constraints not updating with device orientation change(约束不随设备方向更改而更新)

            <bdo id='oB49b'></bdo><ul id='oB49b'></ul>

          • <i id='oB49b'><tr id='oB49b'><dt id='oB49b'><q id='oB49b'><span id='oB49b'><b id='oB49b'><form id='oB49b'><ins id='oB49b'></ins><ul id='oB49b'></ul><sub id='oB49b'></sub></form><legend id='oB49b'></legend><bdo id='oB49b'><pre id='oB49b'><center id='oB49b'></center></pre></bdo></b><th id='oB49b'></th></span></q></dt></tr></i><div id='oB49b'><tfoot id='oB49b'></tfoot><dl id='oB49b'><fieldset id='oB49b'></fieldset></dl></div>
              <tbody id='oB49b'></tbody>
                <tfoot id='oB49b'></tfoot>

                <legend id='oB49b'><style id='oB49b'><dir id='oB49b'><q id='oB49b'></q></dir></style></legend>
              1. <small id='oB49b'></small><noframes id='oB49b'>

                  本文介绍了约束不随设备方向更改而更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 tableView 单元格中有一个

                   func configureColorSlider() {让 colorSlider = ColorSlider()让 xCell = colorCell.contentView.bounds.width让 yCell = colorCell.contentView.bounds.heightcolorSlider.frame = CGRect(x: xCell/4, y: yCell/4, 宽度: 200, 高度: 24)colorSlider.orientation = .horizontalcolorSlider.addTarget(self, action: #selector(ConfigureTimestampTableViewController.changedColor(_:)), for: .valueChanged)colorCell.contentView.addSubview(colorSlider)colorSlider.translatesAutoresizingMaskIntoConstraints = falseNSLayoutConstraint.activate([colorSlider.leadingAnchor.constraint(equalTo: colorLabel.trailingAnchor, 常量: 8),colorSlider.trailingAnchor.constraint(equalTo: colorCell.contentView.trailingAnchor, 常量: -8),colorSlider.topAnchor.constraint(equalTo: colorCell.contentView.topAnchor, 常量: 8),colorSlider.bottomAnchor.constraint(equalTo:colorCell.contentView.bottomAnchor,常量:-8)])}

                  解决方案

                  CALayers 不会响应其父 UIView 被调整大小而调整大小,无论是通过自动布局还是手动.

                  您只需向 ColorSlider 添加代码,当 ColorSilider 的大小/位置发生变化时,该代码会更新图层.幸运的是,UIView 上有一个专门用于此的方法.

                  覆盖 func layoutSubviews() {super.layoutSubviews()gradientLayer.frame = 边界}

                  I have a color slider in a tableView cell that extends from the label to the trailingAnchor of the cell. The issue I am having is when the device orientation changes the color slider does not update its constraints and no longer extends the full length of the cell. Below is my code to set up the constraints on the color slider. Below are images to show the issue I am having. If my phone is already in landscape orientation when I present this scene the color slider extends the full length of the cell as desired. However, if I switch to landscape when already viewing this scene the slider appears as below. Here is the full code if that helps.

                    func configureColorSlider() {
                      let colorSlider = ColorSlider()
                      let xCell = colorCell.contentView.bounds.width
                      let yCell = colorCell.contentView.bounds.height
                      colorSlider.frame = CGRect(x: xCell / 4, y: yCell / 4, width: 200, height: 24)
                      colorSlider.orientation = .horizontal
                      colorSlider.addTarget(self, action: #selector(ConfigureTimestampTableViewController.changedColor(_:)), for: .valueChanged)
                  
                      colorCell.contentView.addSubview(colorSlider)
                  
                      colorSlider.translatesAutoresizingMaskIntoConstraints = false
                      NSLayoutConstraint.activate([colorSlider.leadingAnchor.constraint(equalTo: colorLabel.trailingAnchor, constant: 8),
                                                   colorSlider.trailingAnchor.constraint(equalTo: colorCell.contentView.trailingAnchor, constant: -8),
                                                   colorSlider.topAnchor.constraint(equalTo: colorCell.contentView.topAnchor, constant: 8),
                                                   colorSlider.bottomAnchor.constraint(equalTo: colorCell.contentView.bottomAnchor, constant: -8) ])
                  
                  
                    }
                  

                  解决方案

                  CALayers will not be resized in response to their parent UIView being resized, whether by auto layout or manually.

                  You just need to add code to your ColorSlider that updates the layer when the size/position of the ColorSilider changes. Luckily, there is a method on UIView that is specifically for this.

                  override func layoutSubviews() {
                      super.layoutSubviews()
                      gradientLayer.frame = bounds
                  }
                  

                  这篇关于约束不随设备方向更改而更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

                        <bdo id='NexUQ'></bdo><ul id='NexUQ'></ul>
                          <tbody id='NexUQ'></tbody>

                        <small id='NexUQ'></small><noframes id='NexUQ'>

                      • <tfoot id='NexUQ'></tfoot>

                          <legend id='NexUQ'><style id='NexUQ'><dir id='NexUQ'><q id='NexUQ'></q></dir></style></legend>
                            <i id='NexUQ'><tr id='NexUQ'><dt id='NexUQ'><q id='NexUQ'><span id='NexUQ'><b id='NexUQ'><form id='NexUQ'><ins id='NexUQ'></ins><ul id='NexUQ'></ul><sub id='NexUQ'></sub></form><legend id='NexUQ'></legend><bdo id='NexUQ'><pre id='NexUQ'><center id='NexUQ'></center></pre></bdo></b><th id='NexUQ'></th></span></q></dt></tr></i><div id='NexUQ'><tfoot id='NexUQ'></tfoot><dl id='NexUQ'><fieldset id='NexUQ'></fieldset></dl></div>