我知道我的问题的标题是如此糟糕,但我不知道如何描述它。iphone - 焦点效果(就像UIAlertView)
当UIAlertView弹出时,屏幕上的其他内容(UIAlertView除外)变得有点暗,但可以看到。我将其称为聚焦效果,因为您将清楚直接地知道现在UIAlertView是关注焦点。
那么我该如何实现这种焦点效果呢?
谢谢
我知道我的问题的标题是如此糟糕,但我不知道如何描述它。iphone - 焦点效果(就像UIAlertView)
当UIAlertView弹出时,屏幕上的其他内容(UIAlertView除外)变得有点暗,但可以看到。我将其称为聚焦效果,因为您将清楚直接地知道现在UIAlertView是关注焦点。
那么我该如何实现这种焦点效果呢?
谢谢
只需在要“关注”的视图下方添加半透明视图即可。 简单的例子:
UIView *shieldView = [[[UIView alloc] initWithFrame:myView.bounds] autorelease];
shieldView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
[myView.superview insertSubview:shieldView belowSubview:myView];
UIAlertView
实际上使用的图像具有径向梯度,而不是一个简单的颜色,以突出所述视图的中心。
UIAlertView
的工作原理是这样的。它会淡入Alpha遮罩图像中以淡化背景。一旦动画完成,它就开始对话框的“跳动”动画。
所以要重现它,您需要首先生成一个带有“亮点”的alpha遮罩,其中的对话框将最终放入并淡入。然后使用(几个)帧动画获得反弹效果。
此处了解详情:Creating a Pop animation similar to the presentation of UIAlertView
,使其更好地比“不好说” Could you ...
创建一个笔尖一个UIView(最简单的,如果你的代码的一部分,你需要效果已经在使用一个笔尖),然后在该视图中添加一个半透明图形(带有“焦点”效果)。
在笔尖连接的UIView到图形一个IBOutlet
褪色使用动画到视图层级(OMZ示例显示了此)
我知道此信息是有点老但我认为这可能有助于某人。
使用此代码来生成径向渐变背景:
- (UIImage *)radialGradientImage:(CGSize)size start:(float)start end:(float)end centre:(CGPoint)centre radius:(float)radius{
UIGraphicsBeginImageContextWithOptions(size, YES, 1);
size_t count = 2;
CGFloat locations[2] = {0.0, 1.0};
CGFloat components[8] = {start, start, start, 1.0, end, end, end, 1.0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef grad = CGGradientCreateWithColorComponents (colorSpace, components, locations, count);
CGColorSpaceRelease(colorSpace);
CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(), grad, centre, 0, centre, radius, kCGGradientDrawsAfterEndLocation);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGGradientRelease(grad);
UIGraphicsEndImageContext();
return image;}
定义梯度.h文件中像这样:
UIImageView *gradient;
打电话给你的梯度像这样:
- (void)addGradient{
CGSize size = self.view.bounds.size;
CGPoint centre = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
float startColor = 1.0f;
float endColor = 0.0f;
float radius = MIN(self.view.bounds.size.width/4, self.view.bounds.size.height/4);
gradient = [[UIImageView alloc] initWithImage:[self radialGradientImage:size
start:startColor
end:endColor
centre:centre
radius:radius]];
[gradient setBackgroundColor:[UIColor clearColor]];
[gradient setUserInteractionEnabled:YES];
[gradient setAlpha:0.6f];
[self.view addSubview:gradient];}
这看起来更像一个球体.. – 2013-05-30 16:18:48
我发现,如果你做浮动半径= MIN(self.view.bounds.size.width,self.view.bounds.size.height); 它看起来好多了。 – 2013-05-30 16:34:15
我试过了,但它看起来确实不是很好:( – Jack 2011-05-13 09:34:08
“不好”是什么意思?正如我所说的,这个例子很简单编辑。在真实世界的应用程序中,您很可能会添加淡入/淡出动画,并使用渐变图像而不是简单的颜色... – omz 2011-05-13 09:37:29
我认为我应该首先为shieldView创建淡入/淡出动画,然后弹出注重我的观点? – Jack 2011-05-13 09:41:02