UITextView在UIScrollView上不可见 [英] UITextView not visible on UIScrollView

查看:164
本文介绍了UITextView在UIScrollView上不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我所拥有的是一个UIScrollView,它被约束到主视图的所有四个边,垂直和水平居中,并设置为与视图具有相同的宽度和高度。当我运行应用程序时,我放在UIScrollView之上的所有子视图都会出现,正好在我希望它们的位置,但只有底部的UITextView不是。看起来我已经尝试了各种约束组合,但是当我运行应用程序时它永远不会出现,无论我做什么。以下是界面构建器中约束的屏幕截图:





即使我在运行之前预览文件Main.storyboard,它看起来像这样:






  • UIStoryBoard中左侧面板(文档大纲),您可以按红色箭头显示缺失或冲突的内容。





请查看苹果文档了解更多详情。


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 the UIScrollView, with constraints 0-0-0-0 to leading-top-bottom-trailing to the UIScrollView, and put all your subViews inside that UIView.

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上不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆