I have a laid out views in Storyboard. My structure has the following elements:
- Off Button Background (UIView), Main View
- Off Icon (UIButton), Sub View
- Off Button Label (UILabel), Sub View
Here's how that looks:
Now, I want to animate the "Off Button Bg" to
alpha = 0, but leave the "Off Icon" and "Off Button Label" at
Is that possible given my current structure, where the subviews are nested under "Off Button Bg"? Ideally, I'd like to keep the subviews nested under "Off Button Bg" to enable animating all these elements as a whole in other places.
That is not possible given your current structure. You won't be able to nest those views as subviews without affecting the alpha of those views when you change the alpha of the UIView. The documentation of the alpha property states
However, the transparency imparted by that alpha value affects all of the view's contents, including its subviews. For example, a subview with an alpha value of 1.0 that is embedded in a parent view with an alpha value of 0.5, appears onscreen as if its alpha value is also 0.5.
However, you can achieve that by placing the
Off Icon (button) and
Off Button Label at the same level in the hierarchy as
Off Button Bg, and then setting the constraints of Off Button Bg to align with the other views, but you'll have to manage the alpha values of the views independently.
- Prevent multiple Tap on the same UIButton
- The text in the Modal View Controller does not change in the view controller
- iOS certificate pinning with Swift and NSURLSession
- addressDictionary is deprecated: first deprecated in iOS 11.0 - Use @properties
- How to size a UIScrollView to fit an unknown amount of text in a UILabel?
- VsTac task failed, could not find file appAsTgz.tgz when using global Cordova toolset
- How to add Header with Supplementary view to UiCollectionView in Objective-C?
- iPhone restarts after API call
- Connect Objective C framework to Swift iOS 8 app (Parse framework)
- When should we use “embedded binaries” rather than “Linked Frameworks” in Xcode?