I'm going through my app and I've noticed that when I load certain (4 out of 112 to be exact) objects and load it into a ViewController
with 4 UIStackView
s all written with code (i.e no xib) there is a noticeable lag when loading, and specifically when loading the UIStackView
s. I ran a performance trace and notice the only difference between the views that load quickly and the ones that lag is NSISEngine
methods being called taking about 6x longer (specifically [NSISEngine Optimize]
). Does anyone know why this would only pop up for < 5% of cases?
I am using custom UIStackView
s that are expandable when tapped and this is the code I'm using:
func toggle() {
// only toggle if there's a subView
guard subView != nil else {
return
}
let rotation = isExpanded ? 0 : π / 2
isExpanded = !isExpanded
setSpacing(for: self) // this takes 1e-6s
t1 = Date()
UIView.animate(withDuration: kExpansionTime, animations: {
self.arrowView.transform = CGAffineTransform(rotationAngle: rotation)
self.subView?.isHidden = !self.isExpanded
self.layoutIfNeeded() // no change if this is removed.
}) {_ in
t2 = Date()
print(t2.timeIntervalSince(t1)) // prints ~1s on bad cases and 1e-3 normally
}
}
Edit: This doesn't happen on iOS 10, only in iOS 9 (could this be a bug)?
If anyone was curious as to what was causing they optimization issue, I was using a UILabel
with numberOfLines = 0
. The Label
was in a StackView
that had the following properties
stackView.axis = .vertical
stackView.alignment = .center
stackView.distribution = .fillProportionally
I switched the numberOfLines = 1
and it fixed it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With