Hiding the subview in UIStackview in ios
To answer your first question, if you don't have a need to unhide the subview, the most logical thing to do would be to remove it using removeArrangedSubview(UIView)
. As you might know, the stack view will automagically update its layout whenever views are added, removed, inserted, or hidden/unhidden.
The warning you're getting in the console about the constraints may or may not be related to whatever you've implemented for the subview right now. Did you mention it because you think it might be related?
Hope that helps.
UIStackView Hide View Animation
Just had the same issue.
The fix is adding stackView.layoutIfNeeded()
inside the animation block. Where stackView
is the container of the items you're wishing to hide.
UIView.animate(withDuration: DiscoverHeaderView.animationDuration,
delay: 0.0,
usingSpringWithDamping: 0.9,
initialSpringVelocity: 1,
options: [],
animations: {
clear.isHidden = hideClear
useMyLocation.isHidden = hideLocation
stackView.layoutIfNeeded()
},
completion: nil)
Not sure why this is suddenly an issue in iOS 11 but to be fair it has always been the recommended approach.
UIView hidden is not getting set
Yes, there is a bug / quirk when animating the showing / hiding of arranged subviews in a UIStackView
.
You should be able to correct the issue by adding this to your custom view class:
- (void)setHidden:(BOOL)hidden {
if (self.isHidden != hidden) {
[super setHidden:hidden];
}
}
Here is a complete example that shows the problem, and shows the "fix": https://github.com/DonMag/StackViewBug
Unhiding subviews in stack view causing weird animation
It turns out it was something to do with animating the update of layouts of views pinned to the edge of the UIStackView
. Removing the animation make it work fine.
UIStackView - hide and collapse subview with animation
According to Apple's documentation:
You can animate both changes to the arranged subview’s isHidden property and changes to the stack view’s properties by placing these changes inside an animation block.
I've tested the below code using iOS 12.1 Simulator and it works as expected.
UIView.animate(
withDuration: 2.0,
delay: 0.0,
options: [.curveEaseOut],
animations: {
self.label.isHidden = true
self.label.alpha = 0.0
})
Hiding a UIStackView with nested UISTackviews
Instead of hiding I think it would be better to remove the stackView itself.
myStackView.removeArrangedSubview(playButton)
playButton.removeFromSuperview()
Hope it helps.
Related Topics
React Native App Crashes on Launch Screen on Device
How to Store Custom Objects in Nsuserdefaults
Can You Animate a Height Change on a Uitableviewcell When Selected
How to Change the Name of an iOS App
Uiscrollview Scrollable Content Size Ambiguity
Starting Iphone App Development in Linux
How to Intercept Touches Events on a Mkmapview or Uiwebview Objects
How to Change Navigation Bar Color in iOS 7
-Didselectrowatindexpath: Not Being Called
Draw Text Along Circular Path in Swift For Ios
Remove Alpha Channel in an Image
Programmatically Get Own Phone Number in Ios
How to Make Http Request in Swift
How to Beta Test an Iphone App
Detect If the Device Is Iphone X
Undefined Symbols For Architecture I386: _Objc_Class_$_Skpsmtpmessage", Referenced From: Error