2011-12-30 46 views
0

我在視圖中添加了一個子視圖。我發現它時,感動,當動畫觸摸事件是找到子視圖.. 這裏是代碼...當在iphone中動畫時觸摸子視圖時會發現嗎?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
     UITouch *touch = [touches anyObject]; 
     if ([touch self]) { 
      NSLog(@"View Touched"); 
     } 
     if ([[touch view] isKindOfClass:[Baloon class]]) { 
      NSLog(@"Baloon Touched"); 
     } 
    } 

回答

0

應實現「的touchesBegan」法在你的氣球類,並在「 touchesMove「方法將新的位置設置到Baloon!

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


    NSSet *allTouches = [event allTouches]; 
    switch ([allTouches count]) { 
    case 1: { 
     UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; 

     [self setCenter:[touch locationInView:self.superview]]; 
    } 
     break; 
    default: 
     break; 
    } 
} 
相關問題