2011-08-05 28 views
0

我有一個應用程序,我必須移動圖像,問題出現在鼠標碰到圖像時被移動,但如果它觸及主視圖,整個視圖也在移動。在TouchesMoved上禁用UIView

我試過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 
{ 
} 
+0

你可以發佈你的'touchesEnded'' touchesMoved'和'touchesBegan'代碼嗎? – Hisenberg

+0

你真的不想在touchesMoved中做一個alloc,特別是如果你不釋放它! – ader

+0

實際上,我在每次點擊按鈕時添加了相同的圖像,這就是我需要分配(我認爲)一個初學者對此沒有深入瞭解。 –

回答

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; 
    } 

}

我認爲這將成爲你的目的。

+0

是的,我做了同樣的事情! –

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

假設你的父視圖是不是也是一個UIImageView。

+0

謝謝我解決它。 –