2010-12-11 24 views
5

あまりにUIView内でUIbuttonをドラッグ可能にする方法は?

私は次のコード

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

を使用して、ボタンをドラッグ&ドロップすることができ、私のダッシュボードにボタンをドラッグ&ドロップする必要がありますが、ドラッグアンドドロップは、私はボタンの位置を変更する必要がある一方で、私は必要

注:私は私の質問

答えて

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

使用UIControlEventTouchDragInために私を助けてください唯一のボタン

のためのコードを書きましたあなたはhbdraggablebuttonコントロールを使用することができます

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

ようUIButtonの側面とUIControlEventTouchUpInsideイベント..

関連する問題