我使用核心图形制作了语音气泡的尾部
讲话泡泡的尾部应该移动到我想要的任何点。
问题是当尾巴的末端部分(尖端部分)向下时它工作正常。
但是当气泡倒置时,就像气泡部分在底部,尾部在
顶部,尾部的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);
}