在TouchesMoved上禁用UIView

时间:2011-08-05 08:46:38

标签: iphone objective-c uiview uiviewcontroller touchesmoved

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

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

2 个答案:

答案 0 :(得分:0)

if ([touch.view isKindOfClass:[UIImageView class]]){
imgPimples.center = touchLocation;
}

假设您的父视图也不是UIImageView。

答案 1 :(得分:0)

检查触摸的类是否属于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;
    }

}

我认为这符合你的目的。

相关问题