I have one code that moves uiimage to touch-event
This is true:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[[event allTouches]anyObject];
touchOffset= image.center.x-[touch locationInView:touch.view].x;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[[event allTouches]anyObject];
float distanceMoved=([touch locationInView:touch.view].x+touchOffset)- image.center.x;
float newX= image.center.x+distanceMoved;
if(newX>30 &&newX<290)
image.center=CGPointMake(newX, image.center.y);
if(newX>290)
image.center=CGPointMake(290, image.center.y);
if(newX<30)
image.center=CGPointMake(30, image.center.y);
}
BUT the problem is that I want this action to be performed when the button is pressed (left-right). When I pressed the left button, UIImage moves a little to the left. And when ever I pressed the right button UIImage moved a little to the right side, basically I want the image motion controller with the button only on the x axis of the iphone or pad.
early
Rocky source
share