UITextView not visible on UIScrollView(UITextView 在 UIScrollView 上不可见)
问题描述
好的,所以我有一个 UIScrollView,它被限制在主视图的所有四个侧面,垂直和水平居中,并设置为与视图具有相等的宽度和高度.当我运行应用程序时,我放在 UIScrollView 顶部的所有子视图都会显示出来,正是我希望它们出现的位置,但只有底部的 UITextView 没有.似乎我已经尝试了所有约束组合,但无论我做什么,当我运行应用程序时它都不会出现.下面是界面生成器中的约束截图:
即使我在运行之前预览文件 Main.storyboard,它看起来也是这样的:
但是当我实际运行应用程序时,屏幕缺少 UITextView,即使我以多种方式更改了约束:
任何有关此问题的帮助将不胜感激!提前致谢.
避免将所有子视图直接放在 scrollView
中.自动布局将分解.你需要:
- 在
UIScrollView
内添加一个UIView
,约束条件为0
-0
-0
-0
到leading
-top
-bottom
-trailing
到UIScrollView
,然后把你所有的 subViews 放在那个UIView
里面.
之后,
- UIStoryBoard 的左侧面板(文档大纲),您可以按显示的红色箭头来查看缺少的内容或冲突的内容.
查看 Apple 文档更多细节.
Ok, so what I have is a UIScrollView that is constrained to all four sides of the main view, centered both vertically and horizontally, and set to have equal width and height to the view. All of the subviews that I put on top of the UIScrollView are showing up when I run the app, exactly where I want them to be, but only the UITextView at the bottom is not. It seems like I've tried every combination of constraints but it never appears when I run the app regardless of what I do. Here is a screenshot of the constraints in the interface builder:
And even when I preview the file Main.storyboard before running it looks like this:
But when I actually run the app, the screen is missing the UITextView, even when I alter the constraints in a number of ways:
Any help with this problem will be greatly appreciated! Thanks in advance.
Avoid putting all your subviews directly inside the scrollView
. The autolayout will break apart.
You need to :
- Add a
UIView
inside theUIScrollView
, with constraints0
-0
-0
-0
toleading
-top
-bottom
-trailing
to theUIScrollView
, and put all your subViews inside thatUIView
.
After that, you need to set the contentSize
of your UIScrollView
by code.
Also, you can:
add missing constraints
to see what is missing.
- The left panel in UIStoryBoard (Document Outline), you can press the red arrow showing up to see what is missing or conflicting.
Check out Apple documentation for more details.
这篇关于UITextView 在 UIScrollView 上不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITextView 在 UIScrollView 上不可见
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01