[Objective-C]禁用对 TouchesMoved UIView

发布时间: 2016/9/22 7:49:41
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有我要移动图像的应用程序,问题升起,当鼠标触动它获取移动的图像但如果它触动主视图,整个视图也是移动。

我试过 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
{
}

解决方法 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;
    }

}

我认为它将你的目的。

赞助商