在相同的中心位置缩放圆圈

时间:2015-07-18 02:51:12

标签: ios objective-c core-animation cashapelayer

我正在努力缩放圆圈并保持相同的中心位置,这看起来就像地图上的脉冲圆圈。

AnimationView.m

@property (nonatomic, strong) UIBezierPath *ovalPath;

- (void)drawCircle
{
    UIGraphicsBeginImageContext(self.frame.size);
    CGRect rect = CGRectMake(25.45, 49.25, 5.8, 5.8);
    self.ovalPath = [UIBezierPath bezierPathWithOvalInRect: rect];
    [self.ovalPath fill];
    UIGraphicsEndImageContext();
}

- (void)bumpUpCircle
{
    CAShapeLayer *pathLayer = [CAShapeLayer layer];

    pathLayer.frame     = self.bounds;
    pathLayer.path      = self.ovalPath.CGPath;
    pathLayer.fillColor = [UIColor blackColor].CGColor;
    pathLayer.lineWidth = 2.0f;
    pathLayer.lineJoin  = kCALineJoinBevel;
    [self.layer addSublayer:pathLayer];

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.0, 0.0, 0)];
    animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(10.0, 10.0, 10.0)];
    animation.repeatCount = 1;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.duration = 1;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    [pathLayer addAnimation:animation forKey:@"transform.scale"];
    NSLog(@"%@",NSStringFromCGPoint(self.bounds.origin));
}

然而,缩放位置处于奇怪的位置,而不是圆的中心。

任何想法都将非常感激。感谢。

编辑:

GIF uploaded

1 个答案:

答案 0 :(得分:2)

我建议您使用UIViewController并将其作为子视图添加到UIView中。在下面的示例中,您将获得一个脉冲圆(一个cornerRadius,其半径为UIViewController)在几行中向上和向下缩放。包括这个,例如在viewDidLoad int radius = 100; UIView * circleView = [[UIView alloc] init]; circleView.backgroundColor = [UIColor greenColor]; circleView.frame = CGRectMake(0, 0, radius*2, radius*2); circleView.center = self.view.center; circleView.layer.cornerRadius = radius; [self.view addSubview:circleView]; [UIView animateWithDuration:0.8f delay:0.0f options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{ circleView.transform = CGAffineTransformMakeScale(1.1, 1.1); } completion:^(BOOL fin) { // Do nothing }]; 进行试用。

#define MEX
#include "BallTree.h"
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

  // check for the right number of arguments
  if(nrhs != 2)
    mexErrMsgTxt("Takes 2 input arguments");
  if(nlhs != 1)
    mexErrMsgTxt("Outputs one result (a structure)");

//                                   points, weights
  plhs[0] = BallTree::createInMatlab(prhs[0],prhs[1]);

}