草庐IT

constraint1

全部标签

ios - Swift iOS -Constraint 即使调用了 view.layoutIfNeeded() 也没有动画

我有一个圆形的likeButton,它位于圆形的moreButton后面。likeButton固定到moreButton的centerX和centerY。当我按下moreButton时,我想将likeButton设置为比moreButton高200点的动画。我使用NSLayoutConstraint来跟踪likeButton的centerY并对其进行更改。当我调用UIView.animate并在它的闭包中调用self.view.layoutIfNeeded()时,View没有更新。@objcfuncmoreButtonTapped(){likeButtonCenterY?.isActi

ios - 快照套件 : How to set layout constraints for items in a TableViewCell programatically

我是swift/iOS开发的初学者。来自Web开发人员,与DOM/Box模型相比,布局模型让我完全困惑。我知道这意味着全神贯注,但就我的生活而言,我似乎无法弄明白,我希望像这样的基本示例可能有助于说明一些事情,即使我正在使用DSL像snapkit:http://snapkit.io/我怎样才能为如下布局构建约束:到目前为止,我所知道的显然是错误的如下:label1.snp.makeConstraints{(make)->Voidinmake.leading.equalTo(Style.MARGIN)make.trailing.equalTo(-Style.MARGIN)make.cen

ios - 由于未捕获的异常 'NSGenericException' 而终止应用程序,原因 : 'Unable to activate constraint with anchors

我正在努力寻找和思考这个问题,但我找不到解决它的最佳方案!!我不明白这是什么意思?!Terminatingappduetouncaughtexception'NSGenericException',reason:'Unabletoactivateconstraintwithanchorsandbecausetheyhavenocommonancestor.Doestheconstraintoritsanchorsreferenceitemsindifferentviewhierarchies?That'sillegal.'代码:privateletlogoImageView:UIIma

swift - 错误 "Redundant constraint ' self ' : 'AnyObject' "- where is the `AnyObject` ?

我在开发时发现了一条奇怪的Swift编译器消息(我使用的是Swift4.1):protocolFoo:classwhereSelf:NSObject{//(1)//Redundantconstraint'Self':'AnyObject'}这里发生了什么?首先,这不是多余的。当我写protocolFoo:class{}//(2)我有一个任何对象都可能遵守的协议(protocol),甚至不是从NSObject派生的对象。但我可以创建弱引用:weakvarf:Foo?没问题。另一方面,当我写的时候protocolFoowhereSelf:NSObject{}//(3)我有一个无法生成弱引用

swift - 你能解释/解决这些 'generic constraint' 编译器错误吗?

当我尝试使用associatedType声明协议(protocol)时,我遇到了以下两个编译器错误-不确定什么是genericconstraint。protocolListener{associatedTypeValueTypefunccall(_binding:Binding,value:ValueType)}classBinding{varvalue:T?varlisteners:[Listener]=[]//error1:Protocol'Listener'canonlybeusedasagenericconstraintbecauseithasSelforassociatedt

ios - 自动布局 : Update constraints on UICollectionViewCell doesn't work

我在尝试更新collectionViewCell上的UILabel约束时遇到问题。我的原型(prototype)单元看起来像:我的目标是:我需要编辑红色标签顶部约束的常量,具体取决于我是否隐藏绿色标签。我是如何进行的?我为红色标签(带有红色箭头的标签)上的约束添加了一个IBoutlet:@IBOutletweakvardescriptionTopToPrice:NSLayoutConstraint!然后:descriptionTopToPrice.constant=2self.contentView.setNeedsUpdateConstraints()但它不起作用,并且约束不更新。我

ios - `Protocol can only be used as a generic constraint because it has Self or associated type requirements` 问题

我正在尝试生成一个符合协议(protocol)Protocoling的ViewModel,该协议(protocol)是通用的,并且具有关联的类型。有几个ViewModel符合协议(protocol),所以我正在尝试为viewModel创建一个工厂。我在Swift中遇到了以下错误:Protocol只能用作泛型约束,因为它有Self或关联类型要求示例代码:protocolProtocoling{associatedtypemodulingTypevardata:modulingType{get}}enumMyTypes{casemyNamecasemyAddress}classNameVi

swift - 设置 `constraint.isActive = false` 是否解除约束?

假设我想删除一个约束,传统上我会这样做:view.removeConstraint(constraint)但是,现在有用于安装/卸载约束的新isActive方法。如果我执行以下操作:constraint.isActive=false它会正确地将其从内存中删除吗? 最佳答案 是的,constraint.isActive=false正在做同样的事情:viewThatOwnsConstraint.removeConstraint(constraint)因此,如果唯一保持约束的是View,那么这将正确地将其从内存中删除。证明如下:letvi

ios - "The view hierarchy is not prepared for the constraint" swift 3 错误

我正在尝试添加一个按钮并以编程方式设置约束,但我一直收到此错误并且无法弄清楚我的代码有什么问题。我已经查看了此处的其他问题,但它们对我的情况帮助不大。btn.setTitle("mybtn",for:.normal)btn.setTitleColor(UIColor.blue,for:.normal)btn.backgroundColor=UIColor.lightGrayview.addSubview(btn)btn.translatesAutoresizingMaskIntoConstraints=falseletleft=NSLayoutConstraint(item:btn,a

iOS 10 : NSInvalidLayoutConstraintException: Constraint improperly relates anchors of incompatible types

更新到iOS10后,我在我的一个应用程序上遇到了一堆错误NSInvalidLayoutConstraintException:Constraintimproperlyrelatesanchorsofincompatibletypes:我以前在使用这样的约束时从未遇到过问题,而且我只在我的iOS10设备上遇到过它。有什么想法吗? 最佳答案 你可能正在做这样的事情:NSLayoutConstraint(item:viewA,attribute:.leading,relatedBy:.equal,toItem:parentView,att