CYC

编程入门 行业动态 更新时间:2024-10-04 23:29:04

<a href=https://www.elefans.com/category/jswz/34/1376081.html style=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

本文发布于:2024-02-28 08:36:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1768957.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CYC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!