0

やあ。私はcocos2dの初心者です。(回転ではなく)画像をパンしたい

回転する地球

誰かが私を提案してください。

4

2 に答える 2

1
    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; // calling a method **move**
        [panRecognizer setMinimumNumberOfTouches:1]; // set yourself
        [panRecognizer setMaximumNumberOfTouches:2]; // 
        [panRecognizer setDelegate:self];
        [yourImage addGestureRecognizer:panRecognizer];


/*
    CGFloat firstX;
    CGFloat firstY;
*/

   //---method move---//
 -(IBAction)move:(id)sender
        {
            yourImage.clipsToBounds = YES;
            [yourImage bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
            CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];

            if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
            {

                firstX = [[sender view] center].x;
                firstY = [[sender view] center].y;
            }

            translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);

            [[sender view] setCenter:translatedPoint];

            if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded)
            {

                CGFloat finalX = translatedPoint.x + (.20*[(UIPanGestureRecognizer*)sender velocityInView:self.view].x);
                CGFloat finalY = translatedPoint.y + (.20*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y);

                if(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
                {

                    if(finalX < 0)
                    {

                        finalX = 0;
                    }

                    else if(finalX > 260)
                    {

                        finalX = 260;
                    }

                    if(finalY < 0)
                    {

                        finalY = 0;
                    }

                    else if(finalY > 416)
                    {

                        finalY = 416;
                    }
                }

                else
                {

                    if(finalX < 0)
                    {

                        finalX = 0;
                    }

                    else if(finalX > 416)
                    {

                        finalX = 260;
                    }

                    if(finalY < 0)
                    {

                        finalY = 0;
                    }

                    else if(finalY > 260)
                    {

                        finalY = 416;
                    }
                }

                [UIView beginAnimations:nil context:NULL];
                [UIView setAnimationDuration:.5];

                [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
                [[sender view] setCenter:CGPointMake(finalX, finalY)];
                [UIView commitAnimations];
            }
        }
于 2012-10-19T10:17:02.053 に答える
0

私は提案しUIPanGestureRecognizerます。RayWenderlich の Article hereで、これを行う方法に関する美しいチュートリアルを見つけることができます。お役に立てれば。

于 2012-10-19T10:04:34.360 に答える