This view and it's layer can create a pop and pulse effect.
- Works on any iOS device
To run the example project, clone the repo, and run pod install
from the Example directory first.
BAPulseView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "BAPulseView"
To add a BAPulseView to your app, add the line:
BAPulseView *pulseView = [[BAPulseView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:view];
I added an NSTimer for demo purposes. The timer sets off the funtion popAndPulse
pulseView.center = self.view.center;
[NSTimer scheduledTimerWithTimeInterval:1.0
target:pulseView
selector:@selector(popAndPulse)
userInfo:nil
repeats:YES];
This creates the following view:
Listed below are examples of several properties that you can control.
If you want to round out the few, after you set the cornerRadius and pulseCorderRadius properties:
pulseView.layer.cornerRadius = 20.0f;
pulseView.pulseCornerRadius = 20.0f;
giving a corner radius of half the width and height gives you a circle:
pulseView.layer.cornerRadius = pulseView.frame.size.width/2;
pulseView.pulseCornerRadius = pulseView.frame.size.width/2;
To change the color of the pulse outline, set the pulseStrokeColor property:
pulseView.pulseStrokeColor = [UIColor redColor].CGColor;
By editing the pulseLineWidth property, you can change the width of the pulse outline:
pulseView.pulseLineWidth = 5.0f;
If you want the pulse to extend farther out, pass a float value to the pulseRadius property:
pulseView.pulseRadius = 400.0f;
To increase the time of a pulse, edit the pulseDuration property:
pulseView.pulseDuration = 3.0f;
Listed below are examples of several method you can use to control the animation.
For the default effect, use the following method (or NSTimer if you want it to repeat):
[pulseView popAndPulse];
// pulseView.center = self.view.center;
// [NSTimer scheduledTimerWithTimeInterval:1.0
// target:pulseView
// selector:@selector(popAndPulse)
// userInfo:nil
// repeats:YES];
For just the pop effect, use the following method (or NSTimer if you want it to repeat):
[pulseView pop];
// pulseView.center = self.view.center;
// [NSTimer scheduledTimerWithTimeInterval:1.0
// target:pulseView
// selector:@selector(pop)
// userInfo:nil
// repeats:YES];
For just the pulse effect, use the following method (or NSTimer if you want it to repeat):
[pulseView pulse];
// pulseView.center = self.view.center;
// [NSTimer scheduledTimerWithTimeInterval:1.0
// target:pulseView
// selector:@selector(pulse)
// userInfo:nil
// repeats:YES];
Bryan Antigua, antigua.B@gmail.com
BAPulseView is available under the MIT license. See the LICENSE file for more info.