コアグラフィックを使ってふきだしの尻尾を作りました
スピーチブーブレの尻尾部分は、好きなように任意の場所に移動するはずです。
問題は、尻尾の端の部分(先のとがった部分)が下向きの場合、うまく機能することです。
しかし、泡が逆さまになっているとき、泡の部分が底にあるように、尾の部分は
上では、尾の部分の2つの接続された線が互いに交差し、/\のようになっているときにXを形成します。
誰か助けてくれませんか?
double angle(CGPoint p1, CGPoint p2)
{
//BOOL bRev = TRUE;
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
if (dx == 0 && dy == 0) return 0.0
if (dy == 0) {
if (dx > 0) return 0.0;
else return M_PI;
}
if (dx == 0) {
if (dy > 0) {
double ang = M_PI/2.0;
//if (bRev) ang = M_PI*2 - ang;
return ang;
}
else {
double ang = M_PI/2.0 * 3;
//if (bRev) ang = M_PI*2 - ang;
return ang;
}
}
if (dx > 0) {
if (dy > 0) {
double ang = atan((double)dy/(double)dx); // 1사분면
//if (bRev) ang = M_PI*2 - ang;
return ang;
}
else {
double ang = atan((double)dy/(double)dx) + 2.0*M_PI; // 4사분면
//if (bRev) ang = M_PI*2 - ang;
return ang;
}
}
else {
double ang = atan((double)dy/(double)dx) + M_PI;
//if (bRev) ang = M_PI*2 - ang;
return ang;
}
return 0.0;
}
- (double)degree:(CGPoint)p1 and:(CGPoint)p2
{
double rad = angle(p1, p2);
double deg = rad * 180.0 / M_PI;
if (deg >= 360.0) deg = deg - 360.0;
return (deg);
}
- (CGPoint)getPoint:(CGPoint)cPt Len:(int)len BaseDegree:(double)d1 MoveDegree:(double)d2
{
double radian = 3.14/180.0;
CGPoint pt1;
pt1.x = cPt.x + len*cos((d2-d1)*radian);
pt1.y = cPt.y - len*sin((d2-d1)*radian);
return pt1;
}
- (void)drawRect:(CGRect)rect{
double degree1 = [self degree:CGPointMake(view.frame.origin.x(view.frame.size.width)/2,
view.frame.origin.y+(view.frame.size.height)/2)
and:lastPt];
CGPoint cpt = CGPointMake(view.frame.origin.x+(view.frame.size.width)/2,
view.frame.origin.y+(view.frame.size.height)/2);
CGPoint p1 = [self getPoint:cpt Len:10 BaseDegree:degree1 MoveDegree:90];
CGPoint p2 = [self getPoint:cpt Len:10 BaseDegree:degree1 MoveDegree:-90];
CGPathMoveToPoint(ctx, nil, p1.x, p1.y);
CGPathAddLineToPoint(ctx, nil, lastPt.x, lastPt.y);
CGPathAddLineToPoint(ctx, nil, lastPt.x-2, lastPt.y+2);
CGPathAddLineToPoint(ctx, nil, lastPt.x-4, lastPt.y);
CGPathAddLineToPoint(ctx, nil, p2.x, p2.y);
}