简体   繁体   中英

layoutIfNeeded called on iOS10 but not iOS9

I am using layoutIfNeeded to do some view setup within a UITableViewCell . eg:

override func layoutIfNeeded() {
  super.layoutIfNeeded()
  let rescueButtonCornerLayer = CAShapeLayer()
  let rescueButtonRoundedCornersPath = UIBezierPath(roundedRect: rescueNowButton.bounds, byRoundingCorners: [UIRectCorner.bottomLeft, UIRectCorner.bottomRight], cornerRadii: CGSize(width: MyTheme.cornerRadius, height: MyTheme.cornerRadius))
  rescueButtonCornerLayer.path = rescueButtonRoundedCornersPath.cgPath
  rescueNowButton.layer.mask = rescueButtonCornerLayer
}

This works fine in iOS10 however I've noticed layoutIfNeeded is not called at all in iOS9! Why is this? What can I do to get around it, or where should I place this setup code instead?

Your layout code should be in layoutSubviews , which will be called automatically. You can also call setNeedsLayout and/or layoutIfNeeded to trigger layout, but you should not rely on either of those being called by anyone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM