nslayoutconstraint

How to change or update NSLayoutConstraint programmatically

和自甴很熟 提交于 2019-11-28 21:23:31
I have implemented AutoLayout programmatically using the Code : - (void)addConstraintWithListNavigationViewController:(UIView *)listViewNavigation y:(CGFloat)y height:(CGFloat)height { //WIDTH_ListTableView = 0.4 //set x = 0; NSLayoutConstraint *constraintToAnimate1 = [NSLayoutConstraint constraintWithItem:listViewNavigation attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:0.00 constant:0]; [self.view addConstraint:constraintToAnimate1]; //set y = y; NSLayoutConstraint *constraintToAnimate2 = [NSLayoutConstraint

Update the constant property of a constraint programmatically in Swift?

扶醉桌前 提交于 2019-11-28 21:05:00
I want to animate an object, so I declare a constraint and add it to the view. I then update the constant property of the constraint inside an UIView animation. Why doesn't this code move the object? UIView.animateWithDuration(1, animations: { myConstraint.constant = 0 self.view.updateConstraints(myConstraint) }) duan In order to declare an animation, you cannot re-define the constraint and call updateConstraints . You are supposed to change the constant of your constraint and follow the format below: self.view.layoutIfNeeded() UIView.animateWithDuration(1, animations: { self.sampleConstraint

How to set UILabel only width and height and constraints programmatically

元气小坏坏 提交于 2019-11-28 20:09:03
问题 I want to create a UILabel programmatically with height, width and then I want to add constraints to it also programmatically for positioning the UILabel. Update: I want to create UI like this: How to create this UI All programatically Code to create one label label1 similarly I created two more label label2 and label3 UILabel *label1 = [[UILabel alloc]init]; label1.font = TitleFont; label1.numberOfLines=0; label1.text= @"Descriptions"; label1.lineBreakMode=NSLineBreakByWordWrapping; [label1

What is a 'UIView-Encapsulated-Layout-Width' constraint?

末鹿安然 提交于 2019-11-28 19:05:47
I keep getting 'Unable to simultaneously satisfy constraints' exceptions (Xcode 5, iOS 7, both device and simulator), where one of the constraints in the list is something like this: "<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width' H:[StoryPlayerCell:0x165affc0(0)]>" I did not set this constraint myself. It's also not an NSAutoresizingMaskLayoutConstraint . But where does it come from? And how can I get rid of it? I have no idea. And I can't find anything about 'UIView-Encapsulated-Layout-Width' in the Apple's documentation. Even the Google search returns nothing at all. Any

How to resize a parent view based on the size of subviews layouted with Autolayout

烂漫一生 提交于 2019-11-28 17:17:43
I am preparing a custom view which looks similar to the example shown in the screenshot. I add all user interface components (labels, text fields, radio buttons, ..) at runtime. To position the elements I use Autolayout constraints. This part works fine so far. The number of elements varies from context to context. I wonder how I could use Autolayout constraints to dynamically resize the parent view (most likely the height of the view). The view constraints therefore should consider the height and margins defined for the currently attached subviews. I've done this with the following setup: the

Understanding multiplier in auto layout to use relative positioning

十年热恋 提交于 2019-11-28 16:42:55
I am trying to understand how one can utilize Auto Layout to position items relative to other views percentage-wise. For example, I recently learned that you can specify a view's bottom should lie 4% higher than its superview's bottom by using this: self.view.addConstraint(NSLayoutConstraint(item: label, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 0.96, constant: 0)) This makes sense to me because a multiplier of 1 would align it right at the view's bottom, so you can decrease that amount by 4 percent by changing the multiplier to 0.96. But how can

iOS 7: Misplaced View Frame for “Label - Label” will be different at run time

微笑、不失礼 提交于 2019-11-28 15:57:44
问题 I just finished an app on iOS 6 and bought a developer account a week ago so haven't had much time playing with the iOS 7 SDK. Just downloaded the Golden Master version and trying to upgrade my app to be compatible with iOS 7. I received a lot of warnings saying Misplaced View Frame for "Label - Label" will be different at run time. and I am unable to run the program. The project contains tableview and its is parsing and displaying XML feed from an RSS. How to fix this issue? 回答1: I had the

iOS11 not taking constraints correctly

泪湿孤枕 提交于 2019-11-28 12:44:03
问题 I have an app on the store, in order to support all devices and keyboard I am changing the bottom constraint height according to keyboard height. It is working on all iOS versions except on iOS11. The button is not changing its place as it is shown in the below pictures. Thank you! this is iOS10 preview this is iOS11 preview CODE func keyboardWillShow(notification: NSNotification) { if !keyboardIsHidden{ return; } if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey]

AutoLayout complains about constraints for 2 UITextFields with no borders

好久不见. 提交于 2019-11-28 12:22:07
问题 I am trying to build my login view that has only 2 TextFields, and 2 buttons. I am applying the "Add Missing Constraints" property so that Xcode applies the corresponding constraints to all the elements in my LoginViewController in the storyboard. I am restricting my app to run only in portrait mode, so I am using the "wCompact hRegular" setup. Whenever I run my app and transition to my LoginViewController with a segue, my app displays only one textfield, and shows a bunch of errors in the

How do I animate a NSLayoutConstraint in Swift?

老子叫甜甜 提交于 2019-11-28 12:01:43
My goal is to animate a UIImageView . I declared a NSLayoutConstraint in viewDidLoad . In viewDidLoad , I used this code: UIView.animateWithDuration(1, animations: { myConstraint.constant = 100 self.view.layoutIfNeeded() }, completion: {finished in }) Why doesn't my image move? By the time you hit viewDidLoad , the constraints engine has not yet been applied and the starting location of the views has not yet been established. So, feel free to add the original constraints in viewDidLoad , but you will want to defer the animateWithDuration until later in the process (e.g. viewDidAppear ). For