【问题标题】:Disable UIView on TouchesMoved在 TouchesMoved 上禁用 UIView
【发布时间】:2011-08-05 08:46:37
【问题描述】:

我有一个应用程序,我必须在其中移动图像,当鼠标触摸它移动的图像时会出现问题,但如果它触摸主视图,整个视图也在移动。

我试过 view.userInteractionEnabled=NO;

但在一个移动之后,整个视图都被冻结了。

我希望我的视图是静态的(不移动)

求救!!!

这里是代码

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {  
    UITouch *touch = [[event allTouches] anyObject];

    UIImageView *imgPimples = [[UIImageView alloc]init];
    imgPimples = (UIImageView*)[touch view];
    CGPoint touchLocation = [touch locationInView:imgPimples];
    imgPimples.center = touchLocation;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}

【问题讨论】:

  • 你能把你的touchesEndedtouchesMovedtouchesBegan代码贴出来吗??
  • 您真的不想在 touchesMoved 中进行分配,尤其是在您不释放它的情况下!
  • 实际上我在每次点击按钮时都添加了相同的图像,这就是我需要分配(我认为)我是初学者,所以不要深入了解它。
  • 然后在触摸开始时创建按钮,而不是每次触摸移动时。目前,如果触摸移动,您会一键创建大量图像。

标签: iphone objective-c uiview uiviewcontroller touchesmoved


【解决方案1】:

只需检查所触摸的类是否为 UIImageView 类。

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

UITouch *touch = [[event allTouches] anyObject];
    if ([[touch view] isKindOfClass:[UIImageView class]]) {
        UIImageView *imgPimple;
        imgPimple = (UIImageView *)[touch view]; 
        CGPoint touchLocation = [touch locationInView:imgPimple];
        imgPimple.center = touchLocation;
    }

}

我认为它会达到你的目的。

【讨论】:

    【解决方案2】:
    if ([touch.view isKindOfClass:[UIImageView class]]){
    imgPimples.center = touchLocation;
    }
    

    假设你的父视图不是 UIImageView。

    【讨论】:

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