Iphone 如何停止在objective c中移动图像?
我已经做了编码来检查图像是否穿过了特定区域Iphone 如何停止在objective c中移动图像?,iphone,objective-c,xcode,cocoa,Iphone,Objective C,Xcode,Cocoa,我已经做了编码来检查图像是否穿过了特定区域 -(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;
-(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));
}
但是它不起作用,有人能告诉我如何解决这个问题吗
提前非常感谢只需保留一个单独的
BOOL
值,称为movingabled
,并根据此标志值提前退出touchesMoved
例程(即在调整图像位置之前)。是否满足条件?也就是说,NSLog是否打印该语句?@Aadhira Ya条件满足,但图像仍在移动
[img2Obj setUserInteractionEnabled:FALSE];