我试图淡出整个视图,但只有一个特定的subview
,这会强调subview
的外观更清晰。假设self.view有5 textfields
和2 UIView
为subviews
,我希望强调1 UIView
。有没有办法淡出/在整个self.view中使用5 textfields
和1 UIView
而不触及强调的UIView
?
我已经尝试过使用方法
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
,例如:
[UIView animateWithDuration:0.75
animations:^{
self.view.alpha = 0.5f;
}
completion:^(BOOL finished){self.view.layer.shouldRasterize = NO;}];
但是,似乎整个子视图都受到上面UIView动画的影响。任何建议或提示将不胜感激。
答案 0 :(得分:7)
如果降低UIView
的alpha值,则会降低所有子视图的alpha值。解决问题的方法是单独降低每个子视图的alpha值,除了你想要的那个:
UIView emphasizedView = ...
[UIView animateWithDuration:0.75
animations:^{
for (UIView *view in self.view.subviews) {
if (view != emphasizedView) {
view.alpha = 0.5f;
} else {
view.alpha = 1;
}
}
}
completion:^(BOOL finished){self.view.layer.shouldRasterize = NO;}];