简体   繁体   中英

Animate MainView without SubView iOS

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:

Xcode中的情节提要

Now, I want to animate the "Off Button Bg" to alpha = 0 , but leave the "Off Icon" and "Off Button Label" at alpha=1 .

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.

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