相关疑难解决方法(0)

使用一根手指触摸在中心旋转图像

我想用一根手指触摸在中心点上旋转下面的图像...

我想用触摸旋转图像时显示带有标签的图像值.

我已完成图像旋转,但问题是如何根据旋转设置图像的值.

旋转角度增加,因此我无法设置该值.

谁能帮我?

代码如下

float fromAngle = atan2(firstLoc.y-imageView.center.y, 
                            firstLoc.x-imageView.center.x);

    NSLog(@"From angle:%f",fromAngle);
    float toAngle = atan2( currentLoc.y-imageView.center.y, 
                          currentLoc.x-imageView.center.x);

    NSLog(@"to Angle:%f",toAngle);
    // So the angle to rotate to is relative to our current angle and the
    // angle through which our finger moved (to-from)
    float newAngle =angle+(toAngle-fromAngle);


    NSLog(@"new angle:%.2f",newAngle);


 CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle);

 imageView.transform=cgaRotate;


angle = newAngle;
Run Code Online (Sandbox Code Playgroud)

谁能帮我 ?

iphone image rotation

11
推荐指数
1
解决办法
4909
查看次数

拖动围绕固定点旋转节点

我正在尝试创建一个类似于" 问题轮"的可旋转节点.到目前为止,我具有投掷能力,使用UIPanGestureRecognizer在物理体上添加角度脉冲,效果非常好.我也可以通过触摸来停止旋转.

现在我试图允许使用拖动或滑动手势对车轮进行微调,因此如果玩家对他们最终得到的结果不满意,他们可以手动旋转/拖动/旋转它到他们喜欢的旋转.

目前,我在touchesBegan中保存触摸的位置,并尝试在更新循环中增加节点的zRotation.

旋转不跟随我的手指而且是生涩的.我不确定我是否能够准确读取手指移动或手指的更改位置是否未准确转换为弧度.我怀疑检测到触摸,然后在更新中处理它不是一个很好的解决方案.

这是我的代码.

    override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent?) {
    if let touch = touches.first as? UITouch {
        var location = touch.locationInView(self.view)
        location = self.convertPointFromView(location)

        mostRecentTouchLocation = location

        let node = nodeAtPoint(location)
        if node.name == Optional("left") && node.physicsBody?.angularVelocity != 0
        {
            node.physicsBody = SKPhysicsBody(circleOfRadius:150)
            node.physicsBody?.applyAngularImpulse(0)
            node.physicsBody?.pinned = true
        }
    }
}

    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
        if mostRecentTouchLocation != CGPointZero{
        let node = nodeAtPoint(mostRecentTouchLocation)
        if node.name == …
Run Code Online (Sandbox Code Playgroud)

sprite-kit swift

7
推荐指数
1
解决办法
1571
查看次数

标签 统计

image ×1

iphone ×1

rotation ×1

sprite-kit ×1

swift ×1