这个视图及其层可以创建弹出和脉冲效果。
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
要将 BAPulseView 添加到您的应用程序中,请添加以下行
BAPulseView *pulseView = [[BAPulseView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:view];
我添加了一个 NSTimer 以用于演示目的。定时器会触发 popAndPulse 函数
pulseView.center = self.view.center;
[NSTimer scheduledTimerWithTimeInterval:1.0
target:pulseView
selector:@selector(popAndPulse)
userInfo:nil
repeats:YES];
这将创建以下视图
以下是您可以控制的几个属性的示例。
如果您想使边缘圆润,设置 cornerRadius 和 pulseCorderRadius 属性后
pulseView.layer.cornerRadius = 20.0f;
pulseView.pulseCornerRadius = 20.0f;
将圆角设置为宽度和高度的一半将得到一个圆形
pulseView.layer.cornerRadius = pulseView.frame.size.width/2;
pulseView.pulseCornerRadius = pulseView.frame.size.width/2;
要更改脉冲轮廓的颜色,请设置 pulseStrokeColor 属性
pulseView.pulseStrokeColor = [UIColor redColor].CGColor;
通过编辑 pulseLineWidth 属性,您可以更改脉冲轮廓的宽度
pulseView.pulseLineWidth = 5.0f;
如果您希望脉冲扩展得更远,请传递一个浮点值给 pulseRadius 属性
pulseView.pulseRadius = 400.0f;
要增加脉冲持续时间,请编辑 pulseDuration 属性
pulseView.pulseDuration = 3.0f;
以下是您可以用于控制动画的一些方法的示例。
对于默认效果,请使用以下方法(或将它设置为重复则可以使用 NSTimer)
[pulseView popAndPulse];
// pulseView.center = self.view.center;
// [NSTimer scheduledTimerWithTimeInterval:1.0
// target:pulseView
// selector:@selector(popAndPulse)
// userInfo:nil
// repeats:YES];
对于仅弹出效果,请使用以下方法(或将它设置为重复则可以使用 NSTimer)
[pulseView pop];
// pulseView.center = self.view.center;
// [NSTimer scheduledTimerWithTimeInterval:1.0
// target:pulseView
// selector:@selector(pop)
// userInfo:nil
// repeats:YES];
对于仅脉冲效果,请使用以下方法(或将它设置为重复则可以使用 NSTimer)
[pulseView pulse];
// pulseView.center = self.view.center;
// [NSTimer scheduledTimerWithTimeInterval:1.0
// target:pulseView
// selector:@selector(pulse)
// userInfo:nil
// repeats:YES];
Bryan Antigua,[email protected]
BAFluidView 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。