我正在创建一个自定义警报视图,并将此视图的背景设置为主要为alpha黑色,以使背景视图看起来有点褪色。除了状态栏之外,这是有效的(它保持完全相同)。
使用当前的苹果AlertView框架,当显示警告视图时,整个背景会稍微褪色。如何复制此功能?
编辑
没有一个答案能为我解决这个问题。下面是我为打开AlertView所做的工作:
[self.navigationController.view.superview addSubview:self.alertViewController.view];
然后从viewDidLoad()中的自定义警报视图控制器:
self.view.backgroundColor = COLOR_BLACK_ALPHA;
发布于 2015-10-18 07:48:32
您不能更改状态栏的alpha,只能设置其外观。
UIAlertView是苹果公司的一个组件,因此它使用私有应用程序接口来做你不能做的事情。
我的建议是,在显示视图之前,使用下面的内容为其下面的屏幕创建一个快照(来源:Capture iPhone screen with status bar included
UIView *screenshotView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
然后移除状态栏,并放置图像,模糊图像(可以使用模糊视图完成,或者只是作为图像的效果,然后显示您的视图。
如果你有任何问题,请提出来。
发布于 2015-10-18 08:02:27
您可以通过在添加自定义警报视图之前在Window
中添加自定义覆盖来完成此操作,如下所示:
UIWindow *aMainWindow = [[UIApplication sharedApplication] keyWindow];
self.grayOverlayView = [[MyCustomAlertViewOverlay alloc] initWithFrame:aMainWindow.bounds];
self.grayOverlayView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
[aMainWindow addSubview:self.grayOverlayView];
[aMainWindow addSubview:self.customAlertView];
下面是覆盖图的外观:
@implementation MyCustomAlertViewOverlay
- (void)drawRect:(CGRect)iRect {
CGContextRef aContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(aContext);
CGColorRef aGradientStartColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0].CGColor;
CGColorRef aGradientEndColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.6].CGColor;
NSArray *aColors = [NSArray arrayWithObjects:(__bridge id)aGradientStartColor, (__bridge id)aGradientEndColor, nil];
CGFloat rLocations[2] = {0.0 , 0.5};
CGColorSpaceRef rColorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef rGradient = CGGradientCreateWithColors(rColorSpace, (CFArrayRef) aColors, rLocations);
CGColorSpaceRelease(rColorSpace);
CGPoint aCenter = CGPointMake(iRect.origin.x + iRect.size.width / 2, iRect.origin.y + iRect.size.height / 2);
CGContextDrawRadialGradient(aContext, rGradient, aCenter, 0, aCenter, iRect.size.height, kCGGlyphMax);
CGContextSetRGBFillColor(aContext, 0, 0, 0, 0.0);
CGGradientRelease(rGradient);
CGContextFillRect(aContext, iRect);
CGContextRestoreGState(aContext);
}
发布于 2015-10-18 08:11:58
这个怎么样?
UIWindow *customWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
customWindow.windowLevel = UIWindowLevelStatusBar+1;
customWindow.hidden = NO;
customWindow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
[customWindow makeKeyAndVisible];
现在在customWindow
中,你可以添加任何你想要的东西。
https://stackoverflow.com/questions/33195465
复制相似问题