<bdo id='Iu81U'></bdo><ul id='Iu81U'></ul>
  1. <small id='Iu81U'></small><noframes id='Iu81U'>

    <tfoot id='Iu81U'></tfoot>

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

      iOS 8 上的自动布局问题(代码在 iOS 7 上完美运行)

      时间:2023-09-11
        <bdo id='6TbrK'></bdo><ul id='6TbrK'></ul>

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

            <legend id='6TbrK'><style id='6TbrK'><dir id='6TbrK'><q id='6TbrK'></q></dir></style></legend><tfoot id='6TbrK'></tfoot>
          1. <small id='6TbrK'></small><noframes id='6TbrK'>

                  <tbody id='6TbrK'></tbody>
                本文介绍了iOS 8 上的自动布局问题(代码在 iOS 7 上完美运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个使用 auto-layout 构建的应用程序,当我在 iOS 7 设备上运行它时,一切仍然按预期工作,但是当我在 iOS 8 设备上运行它时,我的一些约束有点古怪.

                I have an app that was built using auto-layout and everything still works as expected when I run it on my iOS 7 device, however when I run it on an iOS 8 device some of my constraints go a little wacky.

                我实际上在另一个应用程序中遇到了类似的问题,但这不是一个大问题.现在,我开始怀疑这是否是 iOS 8 SDK 中的一个错误,或者是否有一种我不知道的在 iOS8 中处理自动布局的新方法.

                I actually experienced a similar issue in another app but it wasn't a big issue. Now, I'm starting to wonder if it is a bug in the iOS 8 SDK or if there is a new way of handling auto layout in iOS8 that I'm not aware of.

                这是我的设置:我有一个 UIView ,其中嵌入了一个 UIImageView .视图和图像视图都有约束固定在底部、前导和后沿到他们的超级视图,常量 = 0.

                Here is my setup: I have a UIView with a UIImageView embedded inside it. Both the view and the image view have constraints pinning their bottom, leading & trailing edges to their superviews with constant = 0.

                UIView 的顶部边缘也固定在其父视图上,并且我有一个连接到约束的 IBOutlet,以便以编程方式对其进行调整.UIImageView 有第四个约束,将其高度固定为设备的高度(在我的例子中是 568).

                The UIView also has its top edge pinned to its superview and I have an IBOutlet connected to the constraint in order to adjust it programatically. The UIImageView has a fourth constraint fixing its height to the height of the device (in my case 568).

                这是我在 iOS 7 中期望/实现的行为:我正在尝试缩小容器视图的高度,并导致图像视图的顶部被切断,而不会改变纵横比(有点像你将图像的顶部裁剪掉了)......这就是为什么我已经固定了图像视图的高度和底部边缘.

                Here is the behavior I am expecting/achieving in iOS 7: I am trying to shrink the height of the container view and cause the top of the image view to be cut off w/o the aspect ratio changing (sort of looks like you cropped the top of the image off)...this is why I have pinned the height of the image view and the bottom edge.

                iOS8 中实际发生的情况:容器视图按预期缩小(它保持固定在侧面和底部并且高度缩小).UIImageView 的行为就好像它有一个带有 cosntant == 0 的顶部空间约束.不是切断图像的顶部,而是整个图像缩小了.由于我的图像处于 AspectFit 模式,因此两侧也会夹入以保持纵横比相同(但 imageView 本身仍应固定在前缘、后缘和底部边缘).

                What actually happens in iOS8: The container view shrinks as expected (it stays pinned to the sides & bottom & the height shrinks). The UIImageView behaves as if it had a top space constraint with cosntant == 0. Instead of cutting off the top of the image, the whole image shrinks down. Since I have the image in AspectFit mode, the sides pinch in as well to keep the aspect ratio the same (but the imageView itself remains pinned to the leading, trailing & bottom edges as it should).

                我是如何做到的:我有一个通知从我的代码的另一部分触发,以调整连接到 IBOutlet 的顶部空间约束.它调用的方法真的很简单:

                How I do it: I have a notification that fires from another part of my code to adjust the top-space constraint hooked up to the IBOutlet. The method it calls is really quite simple:

                - (void) setTopSpaceForContainerView:(NSNotification*) notif{
                    containerView_TopSpace.constant = [[notif.userInfo objectForKey:kTopSpace] intValue];
                    [self.view setNeedsUpdateConstraints];
                    [self.view setNeedsLayout];
                }
                

                其他人有类似经历吗?我正在尝试寻找解决方法,但 iOS 8 似乎决心缩小我的图像.

                Anyone else have a similar experience? I'm trying to find a workaround, but iOS 8 just seems determined to shrink my image.

                非常感谢!

                推荐答案

                这绝对是 iOS 8 的 bug.我可以通过将 setNeedsLayout 发送到容器视图(图像视图的超级视图)来解决它.

                This is definitely an iOS 8 bug. I was able to work around it by sending setNeedsLayout to the container view (the superview of the image view).

                我看到您将 setNeedsLayout 发送到 self.view.如果该代码在您的视图控制器中,那么我猜 self.view 不是容器视图.尝试将 setNeedsLayout 直接发送到容器视图.

                I see that you're sending setNeedsLayout to self.view. If that code is in your view controller, then I guess self.view is not the container view. Try sending setNeedsLayout to the container view directly.

                演示项目在这里.

                这篇关于iOS 8 上的自动布局问题(代码在 iOS 7 上完美运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:AutoLayout 多行 UILabel 截断一些文本 下一篇:UISearchbar TextField 的高度可以修改吗?

                相关文章

                    <bdo id='1NBlx'></bdo><ul id='1NBlx'></ul>

                    <tfoot id='1NBlx'></tfoot>

                    <small id='1NBlx'></small><noframes id='1NBlx'>

                    <legend id='1NBlx'><style id='1NBlx'><dir id='1NBlx'><q id='1NBlx'></q></dir></style></legend>

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