jjzjj

layoutSubview

全部标签

ios - 在 Cocoa Touch 中实现去抖动/合并模式,例如 `layoutSubviews`

许多CocoaTouch类利用合并事件的设计模式。例如,UIViews有一个方法setNeedsLayout,它会在不久的将来调用layoutSubviews。这在许多属性影响布局的情况下特别有用。在每个属性的setter中,您可以调用[selfsetNeedsLayout]这将确保布局将被更新,但如果同时更改多个属性甚至会阻止对布局的许多(可能昂贵的)更新如果在运行循环的一次迭代中多次修改单个属性。其他昂贵的操作,如setNeedsDisplay和drawRect:这对方法遵循相同的模式。实现这种模式的最佳方法是什么?具体来说,我想将一些依赖属性绑定(bind)到一个昂贵的方法,如果

ios - 旋转时调用两次 layoutSubviews

当我的主视图旋转时,我想重新安排subview,所以在我的ViewController中,我重写了willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientationduration:(NSTimeInterval)duration并在那里设置subview的框架。这一切都很好,但在subview中我也覆盖了layoutSubviews所以他们正确地布局自己。但问题是这现在被调用了两次-大概是当我在willAnimateRotationToInterfaceOrientation中设置Frame时一次

ios - UITextField 中的自动布局 : Auto Layout still required after executing -layoutSubviews

我将UITextField子类化以在左侧添加标签。我正在使用自动版式来布置标签。但是,我不断遇到此崩溃:下面是我的布局代码:-(void)updateConstraints{self.segmentLabel.translatesAutoresizingMaskIntoConstraints=NO;NSLayoutConstraint*constraint;constraint=[NSLayoutConstraintconstraintWithItem:self.segmentLabelattribute:NSLayoutAttributeHeightrelatedBy:NSLayou

ios - 每当更改 View 的大小时是否调用 layoutSubviews?

在我的印象中,当autoresizesSubviews=YES时,layoutSubviews应该在每次View大小改变时被调用。但我发现我的观点并非如此。我的期望错了吗? 最佳答案 根据Apple的消息来源,“-[UIViewlayoutSubviews]应该在View大小改变时被调用。”他们还让我引用了iOS的ViewProgrammingGuide:“每当View的大小发生变化时,UIKit应用该View的subview的自动调整行为,然后调用View的layoutSubviews方法让它进行手动更改。您可以在自定义View中

iphone - CustomTableCellView的实现-layoutSubviews需要调用super,NSInternalInconsistencyException

在tableViewxib的自定义单元格中使用autoLayout时,出现以下错误。在iOS6模拟器中运行时CustomCells实现-layoutSubviews需要调用superAssertionfailurein-[CustomCellslayoutSublayersOfLayer:],/SourceCache/UIKit_Sim/UIKit-2372/UIView***Terminatingappduetouncaughtexception'NSInternalInconsistencyException',reason:'AutoLayoutstillrequiredafte

iphone - 如何让 layoutSubviews 在 sizeThatFits 之前被调用?

当我在我的一个View上调用sizeToFit时,我注意到iOS框架首先调用sizeThatFits,然后在该View上调用layoutSubviews。这对我来说是有问题的,因为我的sizeThatFits中的计算取决于我的layoutSubviews的结果。在下面的示例中,subview在layoutSubviews中得到调整,并且此subview的高度在sizeThatFits中使用。目前我的代码无法正常工作,顺序已颠倒。在我的ViewController的viewDidLoad中:UIView*header=[[MyHeaderalloc]init];[headersizeTo

ios - 无法在 UITableviewcell 的 ios 11 layoutsubview subview 中找到 UITableViewCellDeleteConfirmationView?

我必须覆盖Tableviewcell中的高度滑动删除按钮我使用了下面的代码,它在ios10中工作正常但在ios11中我无法在layoutsubview类中找到UITableViewCellDeleteConfirmationViewforeach(varviewsinthis.Subviews){if(views.Class.Name.ToString()==newNSString("UITableViewCellDeleteConfirmationView")){CGRectnewFrame=views.Frame;CGRectnewframe1=newCGRect(newFrame

ios - UITableViewCell 使用自定义 layoutSubviews() 出现在屏幕上后隐藏部分内容

我正在为UITableView苦苦挣扎。正如您在thisvideo中看到的那样在表格View的第三部分中,第三个单元格显示不正确。当我像那样出队时会发生这种情况:letcell=tableView.dequeueReusableCell(withIdentifier:MultipleSelectAnswerSurveyTableViewCellIdentifier,for:indexPath)as!MultipleSelectAnswerSurveyTableViewCellcell.setup(answer:question.answers?[indexPath.row].value

iphone - 在 layoutSubviews 中调用 setNeedsDisplay?

考虑在drawRect:中绘制的具有自定义背景的View。如果View改变大小,则需要重新绘制背景。这是个坏主意吗?-(void)layoutSubviews{[superlayoutSubviews];[selfsetNeedsDisplay];}如果是,考虑到我无法控制谁更改View大小,什么是更好的选择? 最佳答案 不要那样做,没必要。将View的contentMode设置为UIViewContentModeRedraw:UIViewContentModeRedrawRedisplaystheviewwhenthebounds

ios - 使用Autolayout时在layoutSubviews中添加subview是否正确

我编写的代码运行良好@interfaceSubView()@property(nonatomic,strong)UIButton*btn;@end@implementationSubView-(void)layoutSubviews{[superlayoutSubviews];[self.btnremoveFromSuperview];self.btn=[UIButtonbuttonWithType:UIButtonTypeCustom];self.btn.backgroundColor=[UIColorgreenColor];[self.btnsetTitle:@"btn"forSt