nslayoutconstraint

How can I programatically constrain UIButtons in a UIView to proportional widths using NSLayoutConstraints

痞子三分冷 提交于 2020-01-05 08:06:10
问题 I am trying to create a custom keyboard programatically. I have managed to get the functionality of the keyboard working but am struggling with setting the constraints programatically. I have managed to find code to constrain the buttons to be equal sizes in their rows but cannot customise it enough to set the width (or proportional width) of certain buttons. Here is a picture of the keyboard currently Each row is a separate UIView filled with UIButtons corresponding to each key. I then

Can you actually link constraints to utterly different view controllers?

对着背影说爱祢 提交于 2020-01-04 05:25:12
问题 Imagine you have a screen which has a number of view controllers (with container views, or whatever). (If you like, think of an iPad app with many large, complicated areas, each with their own sub-container views for lists, controls, etc.) Even - it may be that you have VCs which are hidden, slidden off screen, perhaps even just in cache and not presented, or you may have a number of screens "stacked on top" of one another so some are not even visible. So say you have a view v var v: UIView

Auto height does not work in uiView in swift 3

痴心易碎 提交于 2020-01-03 00:41:27
问题 I would like to adjust the height according to its content. Currently, I add "Height" in each UIView . These three UIView s are embedded in scrollview. I would like to set the height of " Red " color uiview into " Auto " . If I set that view into auto height and set the top, right,bottom,left specifically, I got error of "Scroll View". So, I fix and add missing constraint, then Xcode will automatically define the height of Red UIView . Let me explain, what I'm doing right now is that I add

Using Constraints To Keep Two TableViews The Same Height & The Same Distance Apart

让人想犯罪 __ 提交于 2020-01-02 19:12:11
问题 Context / What I'd Like to Do I'm building this for iOS 7 I'm using a StoryBoard I have two UITableViews , that I'd like to keep the same height and distance apart, to retain visual consistency between 3.5 & 4 inch devices So on the shift from a 4 inch screen to 3.5 inch screen I'd like for: The table views to get shorter but remain equal in height For the top table view to keep the same y pos For the bottom table view to shift its y pos up to maintain the same distance between the bottom of

How to resize two subviews based on priorities using Cocoa Autolayout?

放肆的年华 提交于 2020-01-02 02:56:09
问题 I am playing with Autolayout in Cocoa and some things are not clear for me. I have 2 views on a window. The width of each view is 1/2 width of the parent window. | | | | | | | View1 | View2 | | | | | | | If I resize a window I want the View2 to resize first. | | | | | | | View1 |View2| | | | | | | When View2 reaches its minimal size I want View1 to be resized to its minimal size. | | | | | | |View1|View2| | | | | | | How can I do that? 回答1: The layout seems a bit unspecified. When does view2

ios change constraint programmatically

淺唱寂寞╮ 提交于 2020-01-01 05:31:12
问题 I am using autolayout with a constraint. The top space to superview is 100 I now want to change this so that when the user rotates the device to landscape The top space to superview is 50 Can this be done at design time? How can this be done at runtime? 回答1: Well, if your 50 px for landscape and 100 for portrait can somehow be derived by relations to sibling subviews and fixed offsets to the bounds of superview, then yes, this can be done "at design time", and that's actually what auto layout

Autolayout Error with UITableView

孤人 提交于 2019-12-30 04:03:22
问题 I have a TableView and I specify the height for each cell using the delegate method tableView:heightForRowAtIndexPath: . When I rotate the view I get this error that I don't quite understand. It can't satisfy the constraint below and breaks it to continue. "<_UIScrollViewAutomaticContentSizeConstraint:0x8e8d040 UITableView:0x9423400.contentHeight{id: 213} == -1568.000000>" Does anyone know what is happening and why I'm breaking this constraint? 回答1: UPDATE : This issue is no longer relevant

Autolayout Error with UITableView

谁说我不能喝 提交于 2019-12-30 04:03:05
问题 I have a TableView and I specify the height for each cell using the delegate method tableView:heightForRowAtIndexPath: . When I rotate the view I get this error that I don't quite understand. It can't satisfy the constraint below and breaks it to continue. "<_UIScrollViewAutomaticContentSizeConstraint:0x8e8d040 UITableView:0x9423400.contentHeight{id: 213} == -1568.000000>" Does anyone know what is happening and why I'm breaking this constraint? 回答1: UPDATE : This issue is no longer relevant

Hiding a UIView using AutoLayout constraints

时光总嘲笑我的痴心妄想 提交于 2019-12-29 10:19:12
问题 From time to time I have a subview that I would like to remove from a layout. Not only should it be hidden, but it should not be considered part of the view's 'flow', so to speak. An example: I am looking for a strategy to hide the orange view programmatically. The layout of the boxes, and their content, is via autolayout. Two things to note: the orange box is defining its vertical height based on the content, plus some top/bottom offsets for margins. So, setting the labels' text to nil will

Why calling setNeedsUpdateConstraints isn't needed for constraint changes or animations?

别等时光非礼了梦想. 提交于 2019-12-28 04:57:05
问题 Readings: From this answer: This is what the accepted answer suggests to animate your view changes: _addBannerDistanceFromBottomConstraint.constant = 0 UIView.animate(withDuration: 5) { self.view.layoutIfNeeded() } Why do we call layoutIfNeeded when we aren't changing the frames. We are changing the constraints, so (according to this other answer) shouldn't we instead be calling setNeedsUpdateConstraints ? Similarly this highly viewed answer says: If something changes later on that