gpt4 book ai didi

iphone - 旋转图像突然翻转

转载 作者:行者123 更新时间:2023-11-28 17:35:07 32 4
gpt4 key购买 nike

我正在使用以下代码通过在左右箭头上开始手势来旋转图像。同时沿旋转方向移动箭头。

- (void)handleRotation:(UIPanGestureRecognizer *)recognizer 
{

UIView* cview = self.superview.superview;

UIView* lView = self.superview;

CGPoint origin = [lView convertPoint: self.center toView: cview];

if (recognizer.state == UIGestureRecognizerStateBegan)
{
if (recognizer.view == leftImage)
{
initialP= [self convertPoint: leftImage.center toView: cview];
}
else
{
initialP = [self convertPoint: rightImage.center toView: cview];
}
}
CGPoint currentP = [recognizer translationInView:cview];
currentP.x += initialP.x;
currentP.y += initialP.y;

CGFloat angle = 0;


CGFloat a = initialP.x - origin.x;
CGFloat b = initialP.y - origin.y;
CGFloat c = currentP.x - origin.x;
CGFloat d = currentP.y - origin.y;
angle = acosf( ((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));


angle += lastReleasedAngle;

if (currentP.y < (currentP.x *(initialP.y - origin.y) + (initialP.x * origin.y - initialP.y * origin.x)) / (initialP.x - origin.x))
{
angle = -angle;
}

if (recognizer.view == leftImage)
{
angle = -angle;
}

if(recognizer.state == UIGestureRecognizerStateBegan ||
recognizer.state == UIGestureRecognizerStateChanged || recognizer.state == UIGestureRecognizerStateEnded)
{

[self setTransform: CGAffineTransformMakeRotation(angle)];
}
if (recognizer.state == UIGestureRecognizerStateEnded)
{

lastReleasedAngle = angle;
}

第一次开始旋转时它工作得很好。比如说,右箭头现在在 0 度。当我从这里开始旋转并在这里释放时它工作正常。当我在其他任何地方释放旋转然后尝试旋转时,图像移动 180 度后开始精确翻转到 180 度。

最佳答案

查看此处左右旋转的示例,并取决于位置 download from here

关于iphone - 旋转图像突然翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10027448/

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