Swetha
Swetha

Reputation: 95

How to stop moving the image in objective c?

I have done a coding to check whether the image crossed particular area or not,

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

CGPoint loc=[touch locationInView:self.view];

if (touch.view==img2Obj) {
    NSLog(@"image2");
    img2Obj.center=loc;

    currentx1=img2Obj.frame.origin.x;
    currenty1=img2Obj.frame.origin.y;
    //NSLog(@"top left corner x and y is %.1f and %.1f",img2Obj.frame.origin.x,img2Obj.frame.origin.y);
    [self isImg1InPos];

}}
-(void)isImg1InPos {

int dx,dy;

dx=currentx1-x1;
dy=currenty1-y1;
if (abs(dx)<5 && abs(dx)<5) {
    NSLog(@"Image must stop moving after this!!!");
    [img2Obj setUserInteractionEnabled:FALSE];
}
//NSLog(@"unsigned int is %d",abs(dx));

}

I want the image to stop moving when when it passes the condition.

[img2Obj setUserInteractionEnabled:FALSE];

But its not working, can anyone tell me how to solve this problem

Many thanks in advance

Upvotes: 0

Views: 102

Answers (1)

Mundi
Mundi

Reputation: 80265

Just keep a separate BOOL value around, called e.g. movingEnabled, and exit your touchesMoved routine early (i.e. before adjusting your image's position) based on this flag's value.

Upvotes: 1

Related Questions