nslayoutconstraint

Moving views with constraints

戏子无情 提交于 2019-11-27 05:30:31
I have a couple views in my view controller that move up when an up swipe is detected then down when a down swipe is detected. I was forcing the views to move by adjusting the y origin using CGRectOffset. I've now applied constraints to my views with IB and I'm not sure whats the best way to move the views so that they end up in the right position on the iphone 5, 6, and 6+. Currently I'm doing something like this: [self.view layoutIfNeeded]; self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant +338; [UIView animateWithDuration:5 animations:^{ [self.view

How can I rearrange views when autorotating with autolayout?

a 夏天 提交于 2019-11-27 05:19:30
问题 I frequently run into this problem where I want my views arranged in one manner for portrait and a somewhat drastically different manner for landscape. For a simplified example, consider the following: Portrait: Landscape: Notice how in portrait the images are stacked vertically, but in landscape, they are side-by-side? Of course, I can manually calculate the positions and sizes, but for more complicated views, this quickly becomes complex. Plus, I'd prefer to use Autolayout so there's less

Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one

女生的网名这么多〃 提交于 2019-11-27 05:06:26
I know how to modify a existing constraint. But I would to know if someone has found a solution to get a constraint without save this one as a property. Current solution to set Constraint height: 1) save NSLayoutConstraint in a variable: NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:myView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:20]; [self.view addConstraint:heightConstraint]; 2) Set the constant of the Constraint saved to "0.0" ( to hide this view)

Width and Height Equal to its superView using autolayout programmatically?

北战南征 提交于 2019-11-27 05:03:25
问题 I've been looking for a lot of snippets in the net and I still can't find the answer to my problem. My question is I have a scrollView(SV) and I want to add a button inside scrollView(SV) programmatically with same width and height of its superview which is scrollView(SV) so that when user rotate the device button will have the same frame of scrollView(SV). how to do the NSLayout/NSLayoutConstraint? thanks 回答1: If someone is looking for a Swift solution – I would create a Swift extension for

Centering subview's X in autolayout throws “not prepared for the constraint”

那年仲夏 提交于 2019-11-27 03:35:24
I have a custom UIView subclass which is being initialized via a nib. In -awakeFromNib , I'm creating a subview and attempting to center it in its superview. [self setInteralView: [[UIView alloc] init]]; [[self internalView] addConstraint: [NSLayoutConstraint constraintWithItem: [self internalView] attribute: NSLayoutAttributeCenterX relatedBy: NSLayoutRelationEqual toItem: self attribute: NSLayoutAttributeCenterX multiplier: 1 constant: 0]]; This breaks, and causes the following output: 2013-08-11 17:58:29.628 MyApp[32414:a0b] The view hierarchy is not prepared for the constraint:

_UIButtonBarStackView: breaking constraint when becomeFirstResponder sent

痴心易碎 提交于 2019-11-27 01:50:04
问题 When jumping from one textfield to an other, get this: translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x6040002806e0 UIKeyboardAssistantBar:0x7f986d40d020.height == 0>", "<NSLayoutConstraint:0x60400008ece0 _UIButtonBarStackView:0x7f986d4041c0.top == UIKeyboardAssistantBar:0x7f986d40d020.top>", "<NSLayoutConstraint:0x60400008ed30 UIKeyboardAssistantBar:0x7f986d40d020.bottom == _UIButtonBarStackView:0x7f986d4041c0.bottom>", "<NSLayoutConstraint:0x60400009f220

UITextView inside UIScrollView with AutoLayout

为君一笑 提交于 2019-11-27 00:32:58
I am trying to place UITextView inside UIScrollView with AutoLayout with no luck. What I have tried is, I placed UIScrollView inside the main view in Storyboard I placed UITextView inside UIScrollView in Storyboard and disabled Scrolling Enabled I set constraints (leading, trailing, top, bottom) on UIScrollView I set constraints (top, leading, trailing, height) on UITextView I created IBOutlet of height constraint of UITextView I set a text (a lot of text which can cause scrolling) on UITextView in viewDidLoad() I set a height constraint of UITextView with the code below. I have tried it right

When should translatesAutoresizingMaskIntoConstraints be set to true?

此生再无相见时 提交于 2019-11-27 00:28:32
问题 I've read the documentation. But I'm still not sure when I need to not set it to false . In the code below if I set it to false I won't see the header at all. If I leave it as true , then everything is fine. The following in View debug hierarchy will give a warning " width and position are ambiguous". func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let header = UIView() header.translatesAutoresizingMaskIntoConstraints = false header.backgroundColor =

How to add Equal Spacing and equal width for button in iOS Auto layout

心不动则不痛 提交于 2019-11-27 00:28:09
Am new to Auto layout constraints in Xcode. I have one Bottom View like UITabBar with 6 UIButtons . Without constraints I aligned those buttons with 5 space padding with each buttons and each buttons has 50 width. Now,I am trying to make it by using Auto layout to support all Screen sizes. In Storyboard constrains I set equal width for 6 buttons and I made 60 space between each buttons. I set first button 0 to leading space and I set the last button 0 to tail constraints. I want the buttons with equal width and flexible spaces between views in all device sizes. Can anyone pleas help me?

What happens with constraints when a view is removed

雨燕双飞 提交于 2019-11-27 00:19:06
问题 The question I have is simple but I couldn't find any information in the documentation. What happens with layout constraints when a view is removed from the view hierarchy (or moved to another view)? For example, let's have container C with subviews A and B . Container C holds some constraints. Then we call [A removeFromSuperview] . What happens with the constraints for A ? What then happens if we add A to C again? 回答1: The constraints are removed. If you add A again, you will have to make