2010-12-11 15 views
5

tengo que arrastrar y soltar el botón en mi tablero de instrumentos i puede arrastrar y soltar el botón utilizando el siguiente códigocómo hacer que el botón UI se pueda arrastrar dentro de UIView?

- (void)viewDidLoad { 
     [super viewDidLoad]; 
    [eventButton addTarget:self action:@selector(draggedOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside]; 
    } 

- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev { 
     CGPoint point = [[[ev allTouches] anyObject] locationInView:self.view]; 
    if(point.y > 22 && point.y <300) 
      c.center = CGPointMake(237, point.y - c.bounds.size.height/2 -5); 
    } 

pero necesito mientras que arrastrar y soltar tengo que cambiar las posiciones de los botones demasiado

nota: i escribió el código sólo por un botón

por favor me ayude a mi pregunta

Respuesta

4
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [eventButton addTarget:self action:@selector(dragOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside]; 
    } 

-(IBAction)dragOut: (id)sender withEvent: (UIEvent *) event { 
UIButton *selected = (UIButton *)sender; 
selected.center = [[[event allTouches] anyObject] locationInView:self.view]; 
} 
0

uso UIControlEventTouchDragIn eventos paralelos y UIControlEventTouchUpInside de UIButton como

// add drag listener 
[button addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside]; 
// add tap listener 
[button addTarget:self action:@selector(wasTapped:) forControlEvents:UIControlEventTouchUpInside]; 

Puede utilizar el control hbdraggablebutton ..

Cuestiones relacionadas