gpt4 book ai didi

ios - UIview Demo 只在一个方向旋转

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:47:58 25 4
gpt4 key购买 nike

我正在使用此示例代码 RotationPie .它是一个轮子,我只想在我的项目中沿一个方向移动或旋转它。我想放置不同的选项,用户将不得不选择其中一个。我希望轮子只朝一个方向旋转。我认为我必须在类 CDCircleGestureRecognizer 中更改此方法中的某些内容,但我不知道是什么。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([self state] == UIGestureRecognizerStatePossible) {
[self setState:UIGestureRecognizerStateBegan];
} else {
[self setState:UIGestureRecognizerStateChanged];
}

// We can look at any touch object since we know we
// have only 1. If there were more than 1 then
// touchesBegan:withEvent: would have failed the recognizer.
UITouch *touch = [touches anyObject];

// To rotate with one finger, we simulate a second finger.
// The second figure is on the opposite side of the virtual
// circle that represents the rotation gesture.

CDCircle *view = (CDCircle *) [self view];
CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds]));
CGPoint currentTouchPoint = [touch locationInView:view];
CGPoint previousTouchPoint = [touch previousLocationInView:view];
previousTouchDate = [NSDate date];
CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);

CGFloat one = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x);

CGFloat two =atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
currentTransformAngle = atan2f(view.transform.b, view.transform.a);


[self setRotation:angleInRadians];

最佳答案

我认为您应该将当前 angleInRadians 存储在一个变量中,并且仅当新角度大于(或小于)当前角度时才允许旋转。

关于ios - UIview Demo 只在一个方向旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12917089/

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