不带子视图的动画主视图 iOS
Animate MainView without SubView iOS
我在 Storyboard 中有布局视图。我的结构包含以下元素:
- 关闭按钮背景(UIView),主视图
- 关闭图标(UIButton),子视图
- 关闭按钮标签 (UILabel),子视图
外观如下:
现在,我想将 "Off Button Bg" 动画化为 alpha = 0
,但将 "Off Icon" 和 "Off Button Label" 保留在 alpha=1
。
考虑到我当前的结构,子视图嵌套在 "Off Button Bg" 下,这可能吗?理想情况下,我希望将子视图嵌套在 "Off Button Bg" 下,以便在其他地方将所有这些元素作为一个整体进行动画处理。
鉴于您当前的结构,这是不可能的。当您更改 UIView 的 alpha 时,您将无法将这些视图嵌套为子视图而不影响这些视图的 alpha。 alpha 属性 的文档说明
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.
但是,您可以通过将 Off Icon
(按钮)和 Off Button Label
放置在层次结构中与 Off Button Bg
相同的级别,然后设置关闭按钮的约束来实现这一点Bg 以与其他视图对齐,但您必须独立管理视图的 alpha 值。
我在 Storyboard 中有布局视图。我的结构包含以下元素:
- 关闭按钮背景(UIView),主视图
- 关闭图标(UIButton),子视图
- 关闭按钮标签 (UILabel),子视图
外观如下:
现在,我想将 "Off Button Bg" 动画化为 alpha = 0
,但将 "Off Icon" 和 "Off Button Label" 保留在 alpha=1
。
考虑到我当前的结构,子视图嵌套在 "Off Button Bg" 下,这可能吗?理想情况下,我希望将子视图嵌套在 "Off Button Bg" 下,以便在其他地方将所有这些元素作为一个整体进行动画处理。
鉴于您当前的结构,这是不可能的。当您更改 UIView 的 alpha 时,您将无法将这些视图嵌套为子视图而不影响这些视图的 alpha。 alpha 属性 的文档说明
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.
但是,您可以通过将 Off Icon
(按钮)和 Off Button Label
放置在层次结构中与 Off Button Bg
相同的级别,然后设置关闭按钮的约束来实现这一点Bg 以与其他视图对齐,但您必须独立管理视图的 alpha 值。