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

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

      <tfoot id='G7eiE'></tfoot>
        • <bdo id='G7eiE'></bdo><ul id='G7eiE'></ul>

        UIPageViewController 中的 UIImageView 调整大小问题

        UIImageView resizing issue in UIPageViewController(UIPageViewController 中的 UIImageView 调整大小问题)

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

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

                <tbody id='W4w27'></tbody>
                <bdo id='W4w27'></bdo><ul id='W4w27'></ul>
                <legend id='W4w27'><style id='W4w27'><dir id='W4w27'><q id='W4w27'></q></dir></style></legend>

                  本文介绍了UIPageViewController 中的 UIImageView 调整大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在构建一个新应用程序,并希望在开始时有一个欢迎演练",其中我有一个故事板,其中包含一系列图像,显示在 UIPageViewController 中.我让它加载图像,所有这些都很好,但是只要图像超出上一个"或下一个"视图控制器,就会调整图像大小.我正在使用 Swift 进行开发.

                  I'm building a new app and wish to have a "Welcome walkthrough" at the beginning wherein I have a storyboard with a series of images presented in a UIPageViewController. I have it loading the images and all of that just fine, however the images are resized whenever they go beyond being the "previous" or "next" ViewController. I am using Swift to develop.

                  这里是该问题的视频:http://youtu.be/dXcjjT-8Bk0

                  我已经尝试了所有不同的视图模式(纵横比拟合、纵横比填充、重绘等),它们的行为都相同.

                  I have tried all of the different View Modes (Aspect fit, aspect fill, redraw etc.) and they all behave the same.

                  我正在使用 Auto-Layout + Size Classes,因为我希望简化针对不同屏幕尺寸的开发.我目前使 UIImage 以正确大小显示的约束是:

                  I am using Auto-Layout + Size Classes as I wish to simplify the development for different screen sizes. The current constraints I have that make the UIImage appear at the right size are:

                  Align Centre X  to Superview
                  Top Space to Top Layout Guide
                  Bottom Space to Bottom Layout Guide + Equals: 50
                  

                  我目前正在使用 Aspect Fit,它为我提供了正确的图像(在他们完成调整大小行为"之后.

                  I am currently using Aspect Fit which gives me the correct image (after they have done their 'resizing behaviour'.

                  谁能进一步指导我如何解决这个问题?

                  Can anyone guide me further as to how to fix this?

                  推荐答案

                  从您的视频中,我注意到您的 UIImageView 总是在顶部调整大小",而不是在底部.这肯定是因为您调用顶部空间到顶部布局指南"的自动布局约束.当您的 UIImageView 的视图控制器正在通过滚动页面视图控制器进行转换时,它不知道顶部布局指南在哪里,所以它的 topLayoutGuide.length 是 <代码>0.只有在动画完成后,视图控制器才会获得 topLayoutGuide.length 的正值.是的,页面视图控制器应该比这更聪明一点,但事实并非如此.
                  您可以停止使用顶部布局指南并相对于其父视图的顶部进行自动布局约束.或者您可以继续使用顶部布局指南,但要考虑它的 length 何时为 0.您可以通过为情节提要的 NSLayoutConstraint 创建一个出口并在包含 UIImageViewViewController 中覆盖 viewWillLayoutSubviews() 来做到这一点>s:

                  From your video, I noticed that your UIImageView is always "resized" at the top, not at the bottom. This is most certainly because of your autolayout constraint you call "Top Space to Top Layout Guide". While your UIImageView's view controller is being transitioned through your scrolling page view controller, it doesn't know where the top layout guide is, so its topLayoutGuide.length is 0. Only after the animation completes does the view controller get a positive value for topLayoutGuide.length. Yes, the page view controller should be a bit smarter than this, but it's not.
                  You can either stop using the top layout guide and make an autolayout constraint relative to the top of its superview. Or you can continue to use the top layout guide but account for when it's length is 0. You can do this by making an outlet for your storyboard's NSLayoutConstraint and overriding viewWillLayoutSubviews() in your ViewController containing your UIImageViews:

                  @IBOutlet weak var topSpaceToTLG: NSLayoutConstraint!
                  var parentTLGlength: CGFloat = 20
                  
                  override func viewWillLayoutSubviews() {
                      if self.topLayoutGuide.length == 0 {
                          // Lengthen the autolayout constraint to where we know the 
                          // top layout guide will be when the transition completes
                          topSpaceToTLG.constant = parentTLGlength
                      } else {
                          topSpaceToTLG.constant = 0
                      }
                  }
                  

                  这将始终将您的 UIImageView 的顶部放在顶部布局指南中,假设状态栏始终是 20 点.在布局子视图之前,它将检查顶部布局指南长度是否为 0 并相应地调整您的自动布局约束.过渡动画完成后,再次触发布局,顶部布局指南长度将是预期值,因此约束常量可以回到0.比硬编码值更好的是在初始化期间传递父视图控制器的确切长度,考虑到顶部布局指南的任何可能更改,例如添加导航栏.

                  This will always put the top of your UIImageView at the top layout guide, assuming that the status bar is always 20 points. Before laying out subviews, it will check to see if the top layout guide length is 0 or not and adjusts your autolayout constraint accordingly. After the transition animation completes, layout is triggered again, and the top layout guide length will be the expected value, so the constraint constant can go back to 0. Even better than hardcoding the value is to pass in the parent view controller's exact length during initialization, accounting for any possible changes to the top layout guide like adding a navigation bar.

                  这篇关于UIPageViewController 中的 UIImageView 调整大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)
                    <tbody id='8HBPf'></tbody>
                  <legend id='8HBPf'><style id='8HBPf'><dir id='8HBPf'><q id='8HBPf'></q></dir></style></legend>

                  <small id='8HBPf'></small><noframes id='8HBPf'>

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