1
在viewDidLoad中,其中CandidateView是自定義視圖 - 控制UIControlEventTouchDragInside問題
for (int i = 0; i < 9 ; i++) {
for (int j = 0; j < 3; j++) {
CandidateView *candView = [[CandidateView alloc]init];
candView.view.frame = CGRectMake(15 + i*186 ,17 + j*145, 158,130);
[candView.btnCandidate addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[mainScroll addSubview:candView.view];
}
}
這是方法
-(void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:button] anyObject];
// get delta
CGPoint previousLocation = [touch previousLocationInView:button];
CGPoint location = [touch locationInView:button];
CGFloat delta_x = location.x - previousLocation.x;
CGFloat delta_y = location.y - previousLocation.y;
// move button
button.center = CGPointMake(button.center.x + delta_x,button.center.y + delta_y);
}
從這個代碼,我能夠在CandidateView移動按鈕..現在我想拖整個CandidateView或應該使UIView而不是UIViewcontroller。 任何人都可以幫助我嗎? 在此先感謝.. :)