我遇到了一些问题:
1 - 我创建了一个简单的自定义UIView(WSSLine),包含起点和终点,width = lenght(startPoint,endPoint),height = 4.一个点是带有x和y的WSSPoint类。 文件WSSLine.m
- (id) initWithFrame:(CGRect)frame
startPoint:(WSSPoint *)start endPoint:(WSSPoint*)end {
float l = [start getLenghtWithOtherPoint:end];
self = [super initWithFrame:CGRectMake([start x],
[start y],
l , [Application getLineWidth]) ];
if (self) {
UIColor* bg = [UIColor colorWithRed:225 green:225 blue:0 alpha:1];
self.backgroundColor = bg;
[self setLenght:l];
float t =[start getAngleWithOtherPoint:end];
self.currentAngle = t;
self.transform = CGAffineTransformRotate(self.transform, t);
}
}
在文件WSSPoint.m函数中getAngleWithOtherPoint:
- (float) getAngleWithOtherPoint: (WSSPoint*) otherPoint {
float a = ([otherPoint y] - [self y])/([otherPoint x] - [self x]);
float arcCos = 1/(sqrtf(1 + a*a));
return acosf(arcCos);
}
和函数getLenghtWithOtherPoint
- (float) getLenghtWithOtherPoint:(WSSPoint *)otherPoint {
float lenghtX = [otherPoint x] - [self x];
float lenghtY = [otherPoint y] - [self y];
return sqrtf(lenghtX*lenghtX + lenghtY*lenghtY);
}
我已尝试使用anchor或view.layer绘制此视图的更多方法,但它并不适用于所有情况。请帮我找到正确的绘画方式。
2-我希望在视图上调整大小但是endPoint不会改变位置。我该怎么办?
非常感谢