CALayerで描いた線の片端(中心)を固定させて任意の角度まで回転させたら止める、
というプログラムを作りたいと思っています。
1回転させることはできたのですが、初めに縦に描いた白線の片端(中心の方)も動いてしまい、
回転させると中心に空円を描くような動きになってしまいます。
アナログ時計のように、片端を固定させたままもう片方の端の座標だけ動かしたいのですが、
どのように書けば良いでしょうか?
よろしくお願い致します。
線の描写はこちらです
- (void)drawInContext:(CGContextRef)ctx { CGMutablePathRef path = CGPathCreateMutable(); //配列で、描画する点を指定します。 指定した点同士をつなぐように直線を描きます。 CGPoint points[] = { CGPointMake(160, 220), CGPointMake(160, 120), }; //点の数を数えます。(配列の要素数をカウント) int numPoints = sizeof(points)/sizeof(points[0]); //点と点の数を指定して直線を描写します。 CGPathAddLines(path, NULL, points, numPoints); CGContextAddPath(ctx, path); CGPathRelease(path); //線の色を設定 UIColor *lineColor = [UIColor colorWithWhite:1.0 alpha:1.0]; CGContextSetStrokeColorWithColor(ctx, lineColor.CGColor); CGContextSetLineWidth(ctx, 5.0); CGContextDrawPath(ctx, kCGPathStroke); }
回転させるコードはこちらです。
//レイヤーを生成します LineLayer *linelayer = [LineLayer layer]; //サイズを指定します linelayer.frame = CGRectInset(self.view.bounds,0.0,0.0); linelayer.anchorPoint = CGPointMake(0.5, 0.5);//アニメーションの中心点の設定 [self.view.layer addSublayer:linelayer]; [linelayer setNeedsDisplay]; CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; animation.toValue = [NSNumber numberWithFloat:M_PI / 2.0]; animation.duration = 0.5; // 0.5秒で90度回転 animation.repeatCount = 1; // 1回くりかえす animation.cumulative = YES; // 効果を累積 [linelayer addAnimation:animation forKey:@"ImageViewRotation"];
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。