简体   繁体   English

如何从自动版式获取真实帧

[英]How can I get real frame from Autolayout

I create a view(width:600) with xib and put a UIScrollView(margin both left and right 20) in it. 我用xib创建了一个view(width:600),并在其中放了一个UIScrollView(左边和右边分别为20)。 I want to get the scrollView's width in code but I get 560 instead. 我想在代码中获取scrollView的宽度,但我却得到560。 I'm new to AutoLayout and really want some help, thanks a lot. 我是AutoLayout的新手,真的很需要帮助,非常感谢。

It's all a question of when you get the scroll view's width in code. 这是何时获取代码中滚动视图宽度的问题。 viewDidLoad is too soon. viewDidLoad为时过早。 viewDidAppear would be okay. viewDidAppear可以。 But the best time is viewDidLayoutSubviews , because that's when layout has been performed and the scroll view's width has been set. 但是最好的时间是viewDidLayoutSubviews ,因为那是执行布局并设置滚动视图的宽度的时间。

You have to load your XIB and call layoutIfNeeded . 您必须加载XIB并调用layoutIfNeeded At the next runloop cycle you will be able to see your actual frame size. 在下一个运行循环周期中,您将能够看到实际的帧大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有Storyboard的Autolayout获取UIView子类的框架? - How can I get the frame of a UIView subclass using Autolayout with Storyboard? 如何使用AutoLayout从UIView子类获取框架 - How to get frame from UIView subclass with AutoLayout 如果初始帧配置错误,如何在使用 AutoLayout 时获取 UIView 的 (x, y)? - How can I get UIView's (x, y) when using AutoLayout if initial frame was misconfigured? UITableViewAutomaticDimension工作,但是如何获得自动布局设置为的框架大小? - UITableViewAutomaticDimension is working but how do I get the frame Size the autolayout set it to? 如何使用自动布局获取实际大小的UIView - How to get real size UIView with autolayout 我可以在 iPad 中使用 Frame 而不是 AutoLayout 吗? - Can I use Frame in iPad,not AutoLayout? 如何让自动布局覆盖 UIImageView 的固有大小? - How can I get autolayout to override a UIImageView's intrinsic size? 如何从 UITextView 获取选定的文本框 - How can I get the selected text frame from a UITextView 自动布局后获取视图的帧 - Get frame of a view after autolayout 在Xcode中,如何使用Tesseract OCR逐帧实时扫描相机预览 - In xcode how can I do a real-time scan of the camera preview frame by frame using Tesseract OCR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM