nslayoutconstraint

Animating Constraint Changes, position animates but height jumps without animation

会有一股神秘感。 提交于 2019-12-05 08:25:13
I have a custom UIView. Within that UIView I have a UILabel with a yellow background containing @"8" called labelWhite . I programmatically create 4 constraints for that UILabel: top, left, width, and height. When I tap the UIView, I change the constant value of the height and animate the layout over 5 seconds. However, the height of the view immediately jumps to the new value, but the y position also changes and jumps to a new value immediately. Then over the 5 second animation, the y position animates back to where it should have stayed all along. You can see a video of it happening here:

Keep UIButtons centered using autolayout in storyboard

送分小仙女□ 提交于 2019-12-05 07:55:59
I have two buttons contained within a view (to be precise, a UITableView footer): I would like to keep the buttons centered (with the gap in-between) regardless of the width of the superview (which will increase, for example, if the device is rotated to portrait orientation). Is there a way to define these autolayout constraints purely in the storyboard, or will I need to use NSLayoutConstraints in code? You can achieve that by adding a constraint for each button to align the leading/trailing to the center of the container view, plus some separation between them. How to do it: For the left

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

点点圈 提交于 2019-12-05 04:15:59
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? The layout seems a bit unspecified. When does view2 start shrinking instead of matching view1's size? I am assuming that the views should be the same size until

NSLayoutConstraint in swift

烂漫一生 提交于 2019-12-04 22:44:22
I am trying to convert the following code to Swift: leftConstraint = [NSLayoutConstraint constraintWithItem:self.contentView attribute:NSLayoutAttributeLeft relatedBy:0 toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; [self.view addConstraint:leftConstraint]; Can someone give me the new syntax to do it in Swift? Copy & paste from the documentation : convenience init(item view1: AnyObject!, attribute attr1: NSLayoutAttribute, relatedBy relation: NSLayoutRelation, toItem view2: AnyObject!, attribute attr2: NSLayoutAttribute, multiplier multiplier: CGFloat, constant c:

iOS开发通过代码方式使用 NSLayoutConstraint + Masonry

感情迁移 提交于 2019-12-04 19:00:16
随着iPhone6/6+设备的上市,如何让手头上的APP适配多种机型多种屏幕尺寸变得尤为迫切和必要。(包括:iPhone4/4s,iPhone5/5s,iPhone6/6s,iPhone 6p/6ps)。 在 iPhone6出现以前,我们接触的iPhone屏幕只有两种尺寸:320 x 480和320 x 568。所以在那个时候使用传统的绝对定位(Frame)方式进行界面控件的布局还是比较轻松的,因为我们只需要稍微调整一下Frame就可以适配这两种 大小的屏幕了。也许这也是为什么虽然AutoLayout从IOS6就已经出现了,但是对于AutoLayout的使用和普及好像都不怎么火热。不过直到 最近随着iPhone6/6+设备的出现,AutoLayout又被众多开发者重新审视和重视了。毕竟APPLE推出AutoLayout就是为了帮助开 发者的APP更方便简单的适配将来不同苹果设备的不同大小屏幕。 首先我们来看一下APPLE官方是如何描述Auto Layout的:Auto Layout 是一个系统,可以让你通过创建元素之间关系的数学描述来布局应用程序的用户界面,是一种基于约束的,描述性的布局系统。所以我们现在要开始摒弃使用传统的 设置 frame 的布局方式的思维来开发视图界面了。因为在 Auto Layout 中,当你描述完视图对象之间的约束之后, Auto Layout

Auto Layout iOS 7 - Can't align right of subview to right of UIScrollView

旧街凉风 提交于 2019-12-04 18:23:05
问题 I am programmatically building a view and using autolayout, no interface builder at all. In a custom ScrollView controller, I am adding a UILabel and a UIButton as subviews. I want to align the label to the left of the screen, and the button to the right of the screen. For some reason, my button only aligns to the left of my scrollview. I've pared down my code so that it's only these two labels and I can't understand why it won't align to the right. HWScrollViewController.m (How I'm

Using Auto Layout, how do I make two labels on the same “line” be dynamic in their widths (adjusting with how wide each one needs to be)?

戏子无情 提交于 2019-12-04 16:33:23
问题 Say I have two UILabels, one is a URL and one is a timer: [http://website.com/link/to/specific/story] [9m 42s] But the "timer" UILabel changes width a lot. Sometimes it is just 12s for example, other times it is 125h 32m 8s . There's a lot of variability. I want the timer UILabel to take up as much width as it needs and the URL label to take up the rest . This means if the timer is longer, shorter URLs, etc. How do I do this in Auto Layout? Preferably in Interface Builder? 回答1: You should set

Where is the Xcode checkbox “Translates Autoresizing Mask Into Constraints”

随声附和 提交于 2019-12-04 15:35:00
问题 In one of the WWDC 2012 videos, Auto Layout By Example, they demo an OS X app using Autolayout, and at about 7 or 8 minutes in, he shows how for a single view, you can uncheck a box in the Attributes Inspector, and the box is called something like "Translates Autoresizing Mask Into Constraints" . Now, I'm well aware of the code equivalent of this box, the translatesAutoresizingMaskIntoConstraints boolean, but I can't seem to find this checkbox anywhere in either iOS or OS X projects. My

Two views, one below another in portrait and side by side in landscape using layout constraints

别来无恙 提交于 2019-12-04 08:42:21
问题 Suppose I have two Text View. In portrait mode, I want these one below another & In landscape mode, I want these to be side by side Is it possible to do that using layout constraints in storyboard using autolayout? If yes, then how? If not, then what would be the other better solution to achieve this. ios6 is my target version 回答1: Here's how you might go about it in code. Basically you need to: a) configure the appropriate NSLayoutConstraint s for the given orientation in

Migrating project to Xcode 7.2 on OS X El Capitan breaks the build

隐身守侯 提交于 2019-12-04 07:43:21
I was running OS X Mavericks before with Xcode 7.1, I just updated to OS X El Capitan and Xcode 7.2. My app was launching fine on the simulator and device without any kind of warnings for storyboard. Now I see a bunch of warnings for missing constraints in storyboard and the app crashes with this error: Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named IBNSLayoutConstraint' I also tried the solution posted on here : Could not instantiate class named IBNSLayoutConstraint I couldn't find placeholder="YES" anywhere in xml