Auto Layout: Create constraint between two views in separate windows

你说的曾经没有我的故事 提交于 2019-12-11 08:29:22

问题


Is it possible to programmatically create a constraint between two views that are in separate windows?

If it is, then I can think of a possible improvement to an answer to "UIView atop the Keyboard similar to iMessage App".

I could set tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive, where tableView displays the messages, and use a dummyInputAccessoryView. Then, I want to use Auto Layout to constrain the height of dummyInputAccessoryView to that of toolbar, which contains inputTextView & sendButton, and the top oftoolbarto that ofdummyInputAccessoryView`.


回答1:


No, I don't think two views in separate windows can be involved in the same constraint because I don't think separate windows can have a common ancestor view.

iOS Developer Library: Auto Layout Guide: Installing Constraints

To make a constraint active, you must add it to a view. The view that holds the constraint must be an ancestor of the views the constraint involves, and should usually be the closest common ancestor. (This is in the existing NSView API sense of the word ancestor, where a view is an ancestor of itself.) The constraint is interpreted in the coordinate system of that view.



来源:https://stackoverflow.com/questions/19532056/auto-layout-create-constraint-between-two-views-in-separate-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!