UIScrollView + 居中视图 + 模糊的可滚动内容大小

UIScrollView + Centered View + Ambigous Scrollable Content Size + many iPhone sizes(UIScrollView + 居中视图 + 模糊的可滚动内容大小 + 许多 iPhone 尺寸)
本文介绍了UIScrollView + 居中视图 + 模糊的可滚动内容大小 + 许多 iPhone 尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

  • 应用程序,应该可以在横向和纵向模式下运行.
  • 顶部带有全尺寸滚动视图的视图.
  • 滚动视图内的一些视图,具有固定的宽度和高度.(添加了 H 和 W 约束)
  • 设置为在容器中水平居中查看滚动视图.(根据约束添加)

我在界面生成器中收到警告具有不明确的可滚动内容宽度".

据我所知,解决此问题的唯一方法是设置尾随和前导约束.但对于不同的 iPhone(5.5"、4.7"、4"),我需要设置不同的尾随和前导约束.

我怎样才能消除这个警告,并且仍然在所有 iPhone 尺寸的固定 W 和 H 的情况下保持居中的水平视图?

我创建 Github repo 来说明这个问题:

附言

我不知道它为什么起作用以及 Xcode 如何检测哪个约束的优先级更高(因为我没有明确为这些约束设置优先级),但如果有人解释,我将不胜感激,为什么它在下面的评论中起作用.

I have:

  • application, that should work in landscape and portrait mode.
  • view with full-size scroll view on top.
  • some view inside scroll view with fixed width and height. (with added H and W constraints)
  • set to view inside scroll view as horizontal centered in container. (added according constraint)

I have warning in interface builder "Has ambiguous scrollable content width".

The only way to fix this problem, that I know - is set trailing and leading constraints. But for different iPhones (5.5", 4.7", 4") I need to set different trailing and leading constraints.

How can I eliminate this warning and still have centered horizontally view with fixed W and H for all iPhone sizes?

I create Github repo to illustrate this problem: ScrollViewAmbigous

This is not duplicate of UIScrollView Scrollable Content Size Ambiguity , but it similar (and not answered although), but this question especially related to different sizes of iPhones.

解决方案

In the morning with a fresh cup of coffee I figured out workaround for this issue!

So, here is the initial state for simplest case:

  1. scrollView with 0 constraints to all edges
  2. Button centered Horizontal and Vertical with fixed Width and Height
  3. And, of course Has ambiguous scrollable content width and Has ambiguous scrollable content height annoying warnings.

All, that we have to do is:

  • Add 2 additional constraints, for example "0" for trailing and/or bottom space for our view (in my case - UIButton)

Important: you have to add trailing and/or bottom constraints. Not "leading and top" - it's not works!

You can check it in my example project, that demonstrating how to fix this issue: ScrollViewAmbigous

P.S.

I don't know why it works and how Xcode detect which constraint is more prioritised (because I'm not set priority for these constraints explicity), but I'll be thankful if someone explain, why it works in comments below.

这篇关于UIScrollView + 居中视图 + 模糊的可滚动内容大小 + 许多 iPhone 尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)