Open thebarndog opened 8 years ago
Where did you use your view?
I had the same results in NibDesignableCollectionReusableView
. But the strange thing is, layoutSubviews()
does get called, and it get's called with correct bounds, but layer does not change.
@startupthekid Did you call super.layoutSubviews()
?
@farzadshbfn Yeah I did. I'm still not sure what was causing it.
@startupthekid Before or after your changes? because I digged into it, layoutSubviews
gets called immediately after awakeFromNib
, with correct bounds, but subviews are not correct yet. So by calling super.layoutSubviews()
my problem was solved.
P.s: I used my own fork of this project (which i hope to merge it into the main one asap), I don't use the extra view as root of the nibDesignable
class. If my solution didn't work for you, try self.subviews[0].setNeedsLayout()
in awakeFromNib
.
I found a bug where if a view inherits from
NibDesignable
,layoutSubviews
gets called with the original sizes from the nibs but not for subsequent resizes. I noticed it when I was making a circular image view and despite doingself.imageView.layer.cornerRadius = self.imageView.frame.size.width /2
inlayoutSubviews
, the image was rounded strangely, even when it had a 1:1 aspect ratio using autolayout.My fix was simply to add
self.layoutIfNeeded
toawakeFromNib
but I suspect the issue goes deeper than that.