IOS动画脉冲圈像地图上的蓝色球

Rod*_*uiz 18 ios ios6

我想知道如何用地图中当前位置的脉动环来实现蓝色球,但是没有mapview.

基本上我想知道当用户触摸屏幕时,在普通UIView(或我的自定义视图)上有一个带有脉动环的蓝色球的最佳方式,该触摸是蓝色球的中心.

我有两个想法,首先我可以实现一个动画,我无法做到,但它可能是可能的.其次,我可以得到一系列图像,如gif,并在用户触摸的任何地方显示.

哪一个是最好的选择?或者有更好的选择吗?

谢谢.

Lev*_*evi 44

试试这个:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
view.backgroundColor = [UIColor blueColor];
view.layer.cornerRadius = 50;

[self.view addSubview:view];

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.duration = 0.2;
scaleAnimation.repeatCount = HUGE_VAL;
scaleAnimation.autoreverses = YES;
scaleAnimation.fromValue = [NSNumber numberWithFloat:1.2];
scaleAnimation.toValue = [NSNumber numberWithFloat:0.8];

[view.layer addAnimation:scaleAnimation forKey:@"scale"];
Run Code Online (Sandbox Code Playgroud)

根据需要设置参数,以修改效果.

编辑:

您必须添加QuartzCore框架,并包含<QuartzCore/QuartzCore.h>此功能.


DrP*_*nce 17

试试这个SWIFT

let view:UIView = UIView(frame: CGRectMake(200, 200, 100, 100))
view.layer.cornerRadius = 50
view.backgroundColor = UIColor.blueColor()

self.view.addSubview(view)

let scaleAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale")

scaleAnimation.duration = 0.5
scaleAnimation.repeatCount = 30.0
scaleAnimation.autoreverses = true
scaleAnimation.fromValue = 1.2;
scaleAnimation.toValue = 0.8;

view.layer.addAnimation(scaleAnimation, forKey: "scale")
Run Code Online (Sandbox Code Playgroud)