как получить кадр изображения при анимации сверху вниз с помощью анимации CABasic - PullRequest
0 голосов
/ 16 апреля 2011

Я использую CABasicAnimation для анимации изображения сверху вниз на экране. Мне необходимо получить кадр изображения во время его анимации сверху вниз ......

Код:

-(id)init
  {
    if(self = [super init])
    {
      self.title =@"Apple Catch";
      mView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,440)];

      // start a timet that will fire 20 times per second
      [NSTimer scheduledTimerWithTimeInterval:(0.9) target:self selector:@selector(onTimer) 
      userInfo:nil repeats:YES];
      self.view=mView;
    }
    return self;

  }

  - (void)onTimer
    {
      CGImageRef imageRef = [[UIImage imageNamed:@"apple.png"] CGImage];
      int startX = round(random() % 460);
      double speed = 1 / round(random() %100) + 1.0;
      CALayer *layer = [CALayer layer];
      layer.name = @"layer";
      layer.contents = imageRef; 
      layer.frame = CGRectMake(startX, self.view.frame.origin.y, CGImageGetWidth(imageRef),
      CGImageGetHeight(imageRef));
      [mView.layer addSublayer:layer];

      CGPoint start = CGPointMake(startX, 0);
      CGPoint end = CGPointMake(startX, self.view.frame.size.height+10);

      CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
      animation.delegate = self;
      animation.fromValue = [NSValue valueWithCGPoint:start];
      animation.toValue = [NSValue valueWithCGPoint:end];
      animation.duration = 10*speed;

      //animation.repeatCount = repeatCount;
      animation.autoreverses = NO;
      animation.removedOnCompletion   = YES;
      animation.fillMode = kCAFillModeForwards;

      [layer addAnimation:animation forKey:@"position"];

      BOOL intersects = CGRectIntersectsRect(layer.frame , dragger.frame);
      printf("\n ==== intersects value :%d",intersects);
    }

Мне нужен кадр изображения, который анимируется в каждой точке его пути на виде.

Можете ли вы предложить код для этого.

Спасибо U

Ответы [ 2 ]

0 голосов
/ 18 апреля 2011

Привет, друг, ты можешь попробовать if (CGRectIntersectsRect (layer.frame, dragger.frame)) {

nslog (@ "hiiii");

}

0 голосов
/ 16 апреля 2011

Используйте свойство presentationLayer CALayer, к которому применяется анимация.

...