私はここで困惑していて、これについていくらかの援助が必要です。テストの目的で、drawRect(以下のコード)を介して描画するUIViewがあります。特定の角度などで円を描くことはできますが、塗りつぶして閉じています。私はそれを開いて撫でる必要があります。私は現在UIBezierPathを使用してこれを行っていますが、これを行うためのより良い方法はありますか?UIBezierPathで必要なように自由端の三角形を描画できますが、必要な角度を指定できません(以下のコードも)。これに関する支援をいただければ幸いです。ありがとう。
下の写真は、特定の角度で描いたときの見た目です。
#import "AngleView.h"
#define DEGREES_TO_RADIANS(degrees) ((M_PI * degrees)/ 180)
@implementation AngleView
-(void)drawRect:(CGRect)rect {
UIBezierPath *aPath = [UIBezierPath bezierPathWithArcCenter:CGPointZero
radius:50
startAngle:0
endAngle:DEGREES_TO_RADIANS(45)
clockwise:NO];
[aPath fill];
}
@end
これが私が特定の角度なしでそれを描くことができる方法です。
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint: CGPointMake(86.5, 33.5)];
[bezierPath addLineToPoint: CGPointMake(60.5, 62.5)];
[bezierPath addLineToPoint: CGPointMake(87.5, 62.5)];
[[UIColor blackColor] setStroke];
bezierPath.lineWidth = 1;
[bezierPath stroke];
1本の線を引く代わりに、同じ点から始まる2つの別々の線を描くことができ、そのうちの1つに角度を付けることができます。
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, 119.5); //here you can set originating point of line
CGContextRotateCTM(context, -45 * M_PI / 180); //Change Angle here -45
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
[bezierPath moveToPoint: CGPointMake(0, 0)];
[bezierPath addCurveToPoint: CGPointMake(39, 0) controlPoint1: CGPointMake(39, 0) controlPoint2: CGPointMake(39, 0)];
[UIColor.blackColor setStroke];
bezierPath.lineWidth = 1;
[bezierPath stroke];
CGContextRestoreGState(context);
//Second UIBezierPath with 0 angle
context = UIGraphicsGetCurrentContext();
UIBezierPath* bezier2Path = UIBezierPath.bezierPath;
[bezier2Path moveToPoint: CGPointMake(0, 119.5)];
[bezier2Path addCurveToPoint: CGPointMake(38.5, 119.5) controlPoint1: CGPointMake(38.5, 119.5) controlPoint2: CGPointMake(38.5, 119.5)];
[UIColor.blackColor setStroke];
bezier2Path.lineWidth = 1;
[bezier2Path stroke];
CGContextRestoreGState(context);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加