gpt4 book ai didi

iphone - UIImageView 如何跟踪顺时针或逆时针用户运动

转载 作者:行者123 更新时间:2023-11-28 20:36:39 25 4
gpt4 key购买 nike

我已经使用这篇文章中的这段代码成功地实现了旋转 uiimageview

iPhone - Wheel tracking finger jumps to same starting position?

我想问其他开发人员的问题是,触摸的用户可以顺时针和逆时针旋转图像。有什么方法可以检测用户移动 View 的方向吗?

它对我很重要,因为我正在制作一个时钟应用程序。我让用户将最小手从 0 分钟一直移动到 60 分钟。当它到达那里时,我将时针向上移动。但是用户可以逆时针旋转分针,在这种情况下我需要将时针向下移动。有什么想法吗?

最佳答案

你可以设置一个名为“lastPoint”的成员变量来记录你上次移动的点

下次可以计算方向


CGPoint lastPoint;


- (void) touchedBegin:(NSSet *)touches withEvent:(UIEvent *)event {
lastPoint = [touch locationInView:self.view];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];

//you can save the point , then used in next time you want

int tInput = [allTouches count]-1;

UITouch *touch =[[allTouches allObjects] objectAtIndex:tInput];
CGPoint location = [touch locationInView:self.view];
float theAngle = atan2( location.y-imageX.center.y, location.x-imageX.center.x );

<strong>float theLastAngle = atan2( lastPoint.y-imageX.center.y, lastPoint.x-imageX.center.x );</strong>

<strong>lastPoint = location;</strong>

// compare theAngle & theLastAngle , so you can know it is clockwise or counterclockwise.
}

关于iphone - UIImageView 如何跟踪顺时针或逆时针用户运动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10201048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com