layoutsubviews

Autolayout in UIView where is safe to ask computed layout values?

不想你离开。 提交于 2020-01-05 07:48:51
问题 I've got this issue. I'm using a collection view as a subview of the main view of a UIViewController . The collection view is pinned to the superview size, thus it has 4 constraints for lead,trail, top and bottom with constants equal to 0. The cell is a subclass to UICollectionViewCell and is composed by: first header view second header view UITableView The collection view cell is loaded from xib and the interface of the views is made for 4 inches devices. The first header view is pinned at

UIScrollView layoutSubviews behavior changes in iOS 5?

自作多情 提交于 2019-12-24 01:23:48
问题 I'm working on a component that is a subclass from UIView and contains a UIScrollView. When scrolling, I noticed different behaviors depending on which SDK I build with. On iOS 4 the layoutSubviews message is send on the scroll view's superview (which is my component) but on iOS 5 it seems that the message is not send anymore... After taking a look at the iOS 5 release notes and changelog, I did not find any mention of such a change. Did I miss somethin? 回答1: In iOS5, layoutSubviews is not

how do I set the size/position of a custom UIView for its placing within a custom UITableViewCell?

点点圈 提交于 2019-12-21 23:31:36
问题 How do I set the size of a subview which is being placed programmatically inside a UITableViewCell? I have a custom (subclassed) UITableViewCell in which part of the cell includes a number of rows (dynamic) which are implemented as a custom UIView. The idea is to create the custom view (which is a row of items) and then when the UITableViewCell hits layoutSubviews it will (a) set itself up re positioning and (b) loop through and call "layoutSubviews" on each of the rows of the custom UIViews

Xcode6, iOS8 and (void)layoutSubviews

爷,独闯天下 提交于 2019-12-18 04:52:47
问题 I have custom UILabel which works fine on iOS6 and iOS7. But on iOS8 this label's (void)layoutSubviews method never get called. I create this label with initWithFrame, so this method should be called - and it's called on another iOS versions. What happens with autoLayout system in iOS8? 回答1: I just want to add this answer because the question title may lead a lot of ppl here with similar issues (like me). With iOS 8 to 8.0.2 LayoutSubviews calls are unreliable. They may not be called ever or

Calling setNeedsDisplay in layoutSubviews?

别等时光非礼了梦想. 提交于 2019-12-10 15:17:23
问题 Consider a view with a custom background that is drawn in drawRect: . If the view changes size, the background need to be redrawn. Is this a bad idea? - (void) layoutSubviews { [super layoutSubviews]; [self setNeedsDisplay]; } If it is, what would be a better alternative considering I can't control who changes the size of the view? 回答1: Dont do that, it's not necessary. Set the contentMode of the view to UIViewContentModeRedraw : UIViewContentModeRedraw Redisplays the view when the bounds

Cannot change frame of a UILabel in a UITableViewCell when first appearing (using Autolayout)

十年热恋 提交于 2019-12-10 12:57:22
问题 I have a prototype cell inside my UITableView which contains a UILabel . I want to dynamically change the size of the label (and the cell) depending on the size of the text in the label. I create the prototype cell in cellForRowAtIndexPath like this: static NSString *CellIdentifier = @"ProgramDetailCell"; ProgramDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell.descriptionLabel.text = self.program.subtitle; return cell; Then my ProgramDetailCell has the

Overriding layoutSubviews when rotating UIView

情到浓时终转凉″ 提交于 2019-12-10 09:44:21
问题 When rotating a scroll view inside a UIView, the scroll view doesnt position correctly using its default autoresizing behaviour. Thus, when rotation occurs, in willRotateToInterfaceOrientation i call [self.view setNeedsLayout]; and my layoutSubviews method is as follows: - (void)layoutSubviews { NSLog(@"here in layoutSubviews"); } But putting a breakpoint on the method, and it never seems to enter the method. Do i need to do something else to get it to work? Thanks. 回答1:

UIView的layoutSubviews和drawRect

只愿长相守 提交于 2019-12-09 12:59:09
UIView的setNeedsDisplay和setNeedsLayout方法。首先两个方法都是 异步 执行的。setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到UIGraphicsGetCurrentContext,就可以画画了。而setNeedsLayout会默认调用layoutSubViews,就可以处理子视图中的一些数据。 综上两个方法都是异步执行的, layoutSubviews方便数据计算,drawRect方便视图重绘 。 先大概看下ios layout机制相关的这几个方法: - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ——————- - (void)layoutSubviews - (void)layoutIfNeeded - (void)setNeedsLayout ——————– - (void)setNeedsDisplay - (void)drawRect 一、 layoutSubviews在以下情况下会被调用: 1、init初始化不会触发layoutSubviews。 2、addSubview会触发layoutSubviews。 3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化。 4

layoutSubviews总结

天涯浪子 提交于 2019-12-09 12:57:29
还是没有理解,浩哥让我在pagecontrol上加红点的demo,失败的原因,其中一点就是layoutsubviews方法会去掉我手动加的view所以没效果,解决方法是在layoutsubviews中加上要调用的方法。 ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit - (void)layoutSubviews - (void)layoutIfNeeded - (void)setNeedsLayout - (void)setNeedsDisplay - (void)drawRect 在苹果的官方文档中强调: You should override this method only if the autoresizing behaviors of the subviews do not offer the behavior you want. layoutSubviews, 当我们在某个类的内部调整子视图位置时,需要调用。 反过来的意思就是说:如果你想要在外部设置subviews的位置,就不要重写。 layoutSubviews是UIView中的属性方法,即只要继承于UIView,就可以使用这个方法,这个方法也很强大,以下是他的触发时机: 1

IOS中UIView的layoutSubviews和drawRect

拈花ヽ惹草 提交于 2019-12-09 12:55:58
UIView的setNeedsDisplay和setNeedsLayout方法。首先两个方法都是 异步 执行的。setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到UIGraphicsGetCurrentContext,就可以画画了。而setNeedsLayout会默认调用layoutSubViews,就可以处理子视图中的一些数据。 综上两个方法都是异步执行的, layoutSubviews方便数据计算,drawRect方便视图重绘 。 先大概看下ios layout机制相关的这几个方法: 1 2 3 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit 1 2 3 4 5 - (void)layoutSubviews - (void)layoutIfNeeded - (void)setNeedsLayout 1 2 3 - (void)setNeedsDisplay - (void)drawRect 一、 layoutSubviews在以下情况下会被调用: 1、init初始化不会触发layoutSubviews。 2、addSubview会触发layoutSubviews。 3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化。 4