我正在尝试呈现 UIView,同时使屏幕的其余部分变暗。但是,我遇到了困难。这是我的代码:
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
self.viewToDarken = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
[self.viewToDarken setBackgroundColor:[UIColor blackColor]];
[self.viewToDarken setAlpha:0.0f];
[window insertSubview:self.viewToDarken aboveSubview:self.hostView];
[self.hostView addSubview:self];
[UIView animateWithDuration:0.25f
delay:0.0
options:UIViewAnimationCurveLinear
animations:^(void) {
[self setFrame:[self destinationFrame]];
if (self.viewToDarken) self.viewToDarken.alpha = 0.7f;
}completion:^(BOOL finished) {
[self notifyDidShow];
}];
但是,我无法让视图变暗以放置在我添加的视图下方(自我)。任何想法为什么这不起作用?
谢谢!