CYC"/>
CYC
手势方向指示
#define radiansToDegrees(x) (180.0 * x / pi)
/// 旋转方向图片
- (void)showFlagImageView:(UIImageView *)imageView start:(CGPoint)start end:(CGPoint)end {// 计算角度CGFloat degrees = [self distanceFromPointX:start distanceToPointY:end];if (!isnan(degrees)) {imageView.hidden = NO;// 计算弧度CGFloat radians = degrees * pi / 180;// 旋转图片imageView.transform=CGAffineTransformMakeRotation(radians);}
}/// start 为圆点 end为终点 计算iOS坐标系角度
-(float)distanceFromPointX:(CGPoint)start distanceToPointY:(CGPoint)end{CGFloat height = end.y - start.y;CGFloat width = end.x - start.x;CGFloat rads = atan(height/width);CGFloat degrees = radiansToDegrees(rads);if (end.x > start.x && end.y < start.y) {// 一象限degrees += 360;} else if (end.x < start.x && end.y < start.y) {// 二象限degrees += 180;} else if (end.x < start.x && end.y > start.y) {// 三象限degrees += 180;} else if (end.x > start.x && end.y > start.y) {// 四象限} else if (end.y == start.y && end.x > start.x) {// x正degrees = 0;} else if (end.x == start.x && end.y > start.y) {// y负degrees = 90;} else if (end.y == start.y && end.x < start.x) {// x负degrees = 180;} else if (end.x == start.x && end.y < start.y) {// y正degrees = 270;} else {// 原点degrees = 0;}return degrees;
}
更多推荐
CYC
发布评论