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

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

      旋转视图是否与自动布局兼容?

      时间:2023-05-18
      <tfoot id='T8ue8'></tfoot>

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

      <legend id='T8ue8'><style id='T8ue8'><dir id='T8ue8'><q id='T8ue8'></q></dir></style></legend>

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

              • 本文介绍了旋转视图是否与自动布局兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我已经学会了如何使用仿射变换旋转视图(请参阅 用于子视图四周的间距约束.

                @IBOutlet 弱变量 rightSpace: NSLayoutConstraint!@IBOutlet 弱变量 leftSpace:NSLayoutConstraint!@IBOutlet 弱 var topSpace:NSLayoutConstraint!@IBOutlet weak var bottomSpace: NSLayoutConstraint!

              • 旋转子视图

                subview.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))

              • 改变了网点的约束

                self.rightSpace.constant = CGFloat(0)self.leftSpace.constant = CGFloat(0)self.topSpace.constant = CGFloat(0)self.bottomSpace.constant = CGFloat(0)

              • 但正是在这一点上,我意识到我真的不需要更改间距值.我希望间距保持为 0.我只需要它自行调整.然而,旋转把这搞砸了.效果如下图所示:

                解决方案

                我在尝试通过 HDMI/AirPlay 从 iOS 运行外部视频到旋转的电视屏幕时遇到了这个问题.

                有时,电视会设置将信号旋转"90 度或 180 度等,但通常它没有该选项.

                使用这样的包装"视图,我可以强制外部屏幕上的视图控制器旋转其内容,而内容实际上并不知道有什么不同.

                让 contentsView = SomeWildCustomViewUsingAutoLayoutEtc()让 wrapper = RotatingWrapperView(contentsView)wrapper.translatesAutoresizingMaskIntoConstraints = falseparentView.addSubview(包装器)//...wrapper.rotation = .upsideDown

                RotatingWrapperView 的来源:https://github.com/quantcon/UIKit/blob/master/AutoLayoutRotationDemo/Views/RotatingWrapperView.swift

                I have learned how to rotate a view with Affine Transforms (see here). I have also learned about Auto Layout (see here and here), and even programmatic Auto Layout (see here and here). However, I don't know how to get Auto Layout to work with a rotated view.

                This image shows what I would like to do:

                I think the trouble comes from the width and the height changing because of the rotation. Is there any way to make a rotated view fill it's superview? Is there some trick to get Auto Layout to work or is it just incompatible after a rotation?

                (I've only learned Swift, but I'd be glad to wade through Objective-C answers if that is what you are more familiar with.)

                Update

                Following @VinayJain's suggestion I did the following:

                • pinned the subview edges to the superview in the storyboard.
                • created IBOutlets for the spacing constraints on all sides of the subview.

                  @IBOutlet weak var rightSpace: NSLayoutConstraint!
                  @IBOutlet weak var leftSpace: NSLayoutConstraint!
                  @IBOutlet weak var topSpace: NSLayoutConstraint!
                  @IBOutlet weak var bottomSpace: NSLayoutConstraint!
                  

                • rotated the subview

                  subview.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
                  

                • changed the constraints from the outlets

                  self.rightSpace.constant = CGFloat(0)
                  self.leftSpace.constant = CGFloat(0)
                  self.topSpace.constant = CGFloat(0)
                  self.bottomSpace.constant = CGFloat(0)
                  

                But it was at this point that I realized that I don't really need to change the spacing value. I want the spacing to remain 0. I just need it to adjust itself. However, the rotation messes that up. The effect is shown in the following image:

                解决方案

                I came across this problem when trying to run external video over HDMI / AirPlay from iOS to a rotated TV screen.

                Sometimes, the TV will have a setting to "rotate" the signal 90-degrees or 180-degrees, etc. but often times it will not have that option.

                With a "wrapper" view like this, I am able to force the view controller on the external screen to rotate its contents without the contents actually being aware that anything is different.

                let contentsView = SomeWildCustomViewUsingAutoLayoutEtc()
                let wrapper = RotatingWrapperView(contentsView)
                wrapper.translatesAutoresizingMaskIntoConstraints = false
                parentView.addSubview(wrapper)
                // ...
                wrapper.rotation = .upsideDown
                

                Source for RotatingWrapperView: https://github.com/quantcon/UIKit/blob/master/AutoLayoutRotationDemo/Views/RotatingWrapperView.swift

                这篇关于旋转视图是否与自动布局兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Android - 如何让 RotateAnimation 更流畅和“物理"? 下一篇:Android 旋转 imageview,我无法在 onAnimationEnd() 中设置 imageview 的最终

                相关文章

                  <legend id='wnpbg'><style id='wnpbg'><dir id='wnpbg'><q id='wnpbg'></q></dir></style></legend>

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

                    • <bdo id='wnpbg'></bdo><ul id='wnpbg'></ul>

                    <tfoot id='wnpbg'></tfoot>

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