7

これは、これまでにこれを試したことがある人にとってはかなり単純で簡単な質問だと確信していますが、私は「高度な」アニメーションと呼ばれるものの初心者です。

CAKeyframeAnimation(「位置」キーパス付き)を使用して、オブジェクトの次の動きを作成しようとしています

http://www.sumopaint.com/files/images800/aeegfexznpohlehd.jpg

UIBezierPath でパスを設定しようとしましたが、その背後にあるロジックが見つからないため、混乱してイライラしました:)

この点について、ご意見をお聞かせいただければ幸いです。...

これは私の基本コードです (より良いアイデアが得られれば、ゼロから作成することもできます :P)

また、完了時にオブジェクトをフェードアウトしたかったのです。アニメーションの完了時に実行するようなセレクターはありますか? ([UIView animateWithDuration] など) ?

UIBezierPath *thumbPath = [UIBezierPath bezierPath];
[thumbPath moveToPoint: P(99,270)];
[thumbPath addCurveToPoint:P(164,260) controlPoint1:P(164,280) controlPoint2:P(164,280)];
[thumbPath addCurveToPoint:P(164,260) controlPoint1:P(260,310) controlPoint2:P(260,310)];

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = thumbPath.CGPath;
pathAnimation.duration = 2.0;
4

2 に答える 2

6

これを行うために私が見つけた最も簡単な方法を、私のようなCAAnimationの初心者のために共有したかっただけです.

UIBezierPath を使用する代わりに、パスの画面上のポイント (x、y) を手動で記述し、それらを使用してパスを作成し、必要な曲線を作成しました。非常に便利で簡単です。

これがお役に立てば幸いです:

NSArray *myPoints = [NSArray arrayWithObjects: 
                             [NSValue valueWithCGPoint:P(77,287)],
                             [NSValue valueWithCGPoint:P(97,270)],
                             [NSValue valueWithCGPoint:P(112,260)],
                             [NSValue valueWithCGPoint:P(130,250)],
                             [NSValue valueWithCGPoint:P(154,245)],
                             [NSValue valueWithCGPoint:P(174,250)],
                             [NSValue valueWithCGPoint:P(193,260)],
                             [NSValue valueWithCGPoint:P(210,270)],
                             [NSValue valueWithCGPoint:P(231,287)],
                             nil];

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 77, 280);

for(NSValue *val in myPoints){
    CGPoint p = [val CGPointValue];
    CGPathAddLineToPoint(path, NULL, p.x, p.y);
}

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = path;
CGPathRelease(path);
于 2011-08-20T10:04:04.070 に答える
-2

touches メソッドを実装し、begin メソッドに開始点を追加します

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:myImageView];
    StartDrawPoint = point;
}

TouchMoved で draw メソッドを呼び出す

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPoint = [touch locationInView:myImageView];
    [self drawline:currentTouchPoint ToPoint:StartDrawPoint];
}

Draw メソッド

- (void)drawline:(CGPoint)FromPoint ToPoint:(CGPoint)ToPoint{
   UIGraphicsBeginImageContext(myImageView.frame.size);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0,1.0,1.0, 1.0);
    [imgView.image drawInRect:CGRectMake(0, 0, myImageView.frame.size.width, myImageView.frame.size.height)];
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:FromPoint];
    [path addLineToPoint:ToPoint];
    [path setLineWidth:5.0f];
    [path stroke];
    [path closePath];
    myImageView.image = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
}
于 2011-12-15T09:15:19.677 に答える