2015-03-03 3 views
1

Я хочу реализовать анимацию, ее вид с точки зрения начинает расширяться круговым и заполнять весь вид. Я выполнил следующий код, но он не заполняет точку зрения циркулярно. Есть идеи?Циклическая анимация

- (void)viewDidLoad { 
[super viewDidLoad]; 
myView =[[UIView alloc]init]; 
myView.frame=CGRectMake(self.view.frame.size.width/2,self.view.frame.size.height/2+100, .1, .1); 
myView.backgroundColor=[UIColor redColor]; 
[self.view addSubview:myView]; 
[self animate]; 
} 

-(void)animate{ 
[UIView animateWithDuration:1.0 
         delay: 0.0 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        [self setRoundedView: myView toDiameter:1000]; 

       } 
       completion:nil]; 
} 


-(void)setRoundedView:(UIView *)roundedView toDiameter:(float)newSize; 
{ 
CGPoint saveCenter = roundedView.center; 
    CGRect newFrame = CGRectMake(roundedView.frame.origin.x,  roundedView.frame.origin.y, newSize, newSize); 
roundedView.frame = newFrame; 
roundedView.layer.cornerRadius = newSize/2.0; 
roundedView.center = saveCenter; 
} 
+0

http://stackoverflow.com/a/10902063/4030971 - это поможет. Просто нужно внести некоторые изменения в соответствии с вашими требованиями. –

ответ

0

Вы можете создать слой CAShape с круговым контуром Безье и анимировать свойство пути.

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath: @"path"]; 

Проверить здесь для получения более подробной информации: Animating CAShapeLayer size change

Если вы не хотите использовать CAnimation вы можете просто масштабировать округлый вид, как это:

[UIView animateWithDuration:1.0 
        delay: 0.0 
       options:UIViewAnimationOptionCurveEaseOut 
      animations:^{ 
       myView.transform = CGAffineTransformMakeScale(scaleX,scaleY); 

      } 
      completion:nil]; 
0

Попробуйте этот код. Может быть полезно.

// Set up the shape of the circle 
    int radius = 100; 
    CAShapeLayer *circle = [CAShapeLayer layer]; 
    // Make a circular shape 
    circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) 
              cornerRadius:radius].CGPath; 
    // Center the shape in self.view 
    circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, 
            CGRectGetMidY(self.view.frame)-radius); 

    // Configure the apperence of the circle 
    circle.fillColor = [UIColor redColor].CGColor; 
    circle.strokeColor = [UIColor blackColor].CGColor; 
    circle.lineWidth = 5; 

    // Add to parent layer 
    [self.view.layer addSublayer:circle]; 

    // Configure animation 
    CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 
    drawAnimation.duration   = 10.0; // "animate over 10 seconds or so.." 
    drawAnimation.repeatCount   = 1.0; // Animate only once.. 

    // Animate from no part of the stroke being drawn to the entire stroke being drawn 
    drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; 
    drawAnimation.toValue = [NSNumber numberWithFloat:1.0f]; 

    // Experiment with timing to get the appearence to look the way you want 
    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 

    // Add the animation to the circle 
    [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"]; 
+0

Я думаю, что вы не поняли, это для рисования круга по его окружности –

Смежные вопросы