【问题标题】:How to stop moving the image in objective c?如何停止在目标 c 中移动图像?
【发布时间】:2012-10-18 16:32:08
【问题描述】:

我已经进行了编码来检查图像是否越过特定区域,

-(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));

}

我希望图像在满足条件时停止移动。

[img2Obj setUserInteractionEnabled:FALSE];

但它不起作用,谁能告诉我如何解决这个问题

在此先感谢

【问题讨论】:

  • 条件是否满足?即,NSLog 是否打印该语句?
  • @Aadhira Ya 条件满足但图像仍在移动

标签: iphone objective-c xcode cocoa


【解决方案1】:

只需保留一个单独的 BOOL 值,例如称为movingEnabled,并根据此标志的值尽早(即在调整图像位置之前)退出您的 touchesMoved 例程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多