2011-05-18 4 views
10

UILongPressGestureRecognizer hareketi tetiklendiğinde UIButtons'un sürüklenip bırakılabileceği bir uygulama oluşturmaya çalışıyorum.UILongPressGestureRecognizer

Ben: Bu bir düğme (yani ivar button) ile büyük işler

UIGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
initWithTarget:self action:@selector(handleLongPress:)]; 

Ve

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer { 
    CGPoint location = [recognizer locationInView:self.view]; 

    switch (recognizer.state) { 
     case UIGestureRecognizerStateBegan: 
      //NSLog(@"handleLongPress: StateBegan"); 
      break; 
     case UIGestureRecognizerStateChanged: 
      if(location.y > 75.0 && location.x > 25 && location.x < 300) 
       button.frame = CGRectMake(location.x-25, location.y-15, 50, 30);   
      break; 
     case UIGestureRecognizerStateEnded: 
      //NSLog(@"handleLongPress: StateEnded"); 
      break; 
     default: 
      break; 
    } 
} 

. HandleLongPress işlevine basılan geçerli düğmeye nasıl gönderebilirim? Ben Sen handleLongPress içine tüm düğmesi aracılığıyla döngü gerekecek sender

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer:(id)sender { 
    CGPoint location = [recognizer locationInView:self.view]; 

    switch (recognizer.state) { 
     case UIGestureRecognizerStateBegan: 
      //NSLog(@"handleLongPress: StateBegan"); 
      break; 
     case UIGestureRecognizerStateChanged: 
      if(location.y > 75.0 && location.x > 25 && location.x < 300) 
       sender.frame = CGRectMake(location.x-25, location.y-15, 50, 30);   
      break; 
     case UIGestureRecognizerStateEnded: 
      //NSLog(@"handleLongPress: StateEnded"); 
      break; 
     default: 
      break; 
    } 
} 

cevap

-2

geçmek nerede Başka bir deyişle, aşağıdaki gibi bir şey yapmak istiyorum. KonumuInInView ve pointInside: withEvent: basma parmağının altında hangi düğmenin olduğunu belirlemek için.

İlgili konular