ios - 通过触摸旋转图像

标签 ios cocoa-touch uitouch

我制作了一个应用程序,用时钟设置 sleep 定时器。基本上它是一个时钟,用户可以用一只手移动它来设置他的 sleep 时间。我试着用<旋转图像strong>uitouch 但它从中间旋转但我希望它从尖端旋转。其次我希望图像仅在用户触摸图像尖端时旋转但在我的项目中图像也在使用时旋转触摸屏幕的任何部分。我也想在两个方向上旋转图像,但在我的项目中,由于这种方法,它只能顺时针移动

image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));

谁能给我一些提示或解决方案,告诉我如何做到这一点?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //

        touch = [[event allTouches] anyObject];
        touchLocation = [touch locationInView:touch.view];

        NSLog(@"began");

    }


    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        // get touch event

        [image.layer setAnchorPoint:CGPointMake(0.0,0.0)];



        if ([touch view] == image) {
            image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));

        //image.center = touchLocation;
    }

      }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
        NSLog(@"end");



    }

最佳答案

具体来说,可以自定义一个rotateView,然后:

1:在“touchesBegan”的委托(delegate)方法中,获取手指的initialPoint和initialAngle。

2:在“touchesMoved”期间,获取新的手指点:

CGPoint newPoint = [[touches anyObject] locationInView:self];
[self pushTouchPoint:thePoint date:[NSDate date]];
double angleDif = [self angleForPoint:newPoint] - [self angleForPoint:initialPoint];
self.angle = initialAngle + angleDif;
[[imageView layer] setTransform:CATransform3DMakeRotation(angle, 0, 0, 1)];

3:最后,在“touchesEnded”中你可以计算最终的AngularVelocity。

如果有什么不明白的,想了解更多细节,你可以回信。

关于ios - 通过触摸旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5178022/

相关文章:

ios - 在屏幕 IOS 上获取完整的 Touch Area/Space

ios - 同时移动2个物体

ios - 将 NSDecimal 设置为零

ios - 总是将除一个对象之外的两个对象添加到数组中(否则错误)

ios - Iphone,获取 NSArray 中的国家/地区列表

ios - 在显示数据之前处理异步下载延迟

swift - 如何快速获取连续触摸的初始位置

ios - Swift Charts - 明确识别特定条目

ios - 在保持图像质量的同时将 UIImage 剪切到自定义 UIBezierPath

ios - viewWillTransitionToSize :withTransitionCoordinator: called when app goes into the background or inactive