问题
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 of
toolbarto that of
dummyInputAccessoryView`.
回答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