Iphone uicontrolEventTouchDragins问题
在Viewdidload中,CandidateView是自定义viewcontrollerIphone uicontrolEventTouchDragins问题,iphone,ios,objective-c,Iphone,Ios,Objective C,在Viewdidload中,CandidateView是自定义viewcontroller 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,1
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];
}
}
根据这段代码,我可以在CandidateView中移动一个按钮。。现在我想拖动整个候选视图,或者我应该使用UIView而不是UIViewcontroller。
有人能帮我吗??
提前感谢:)制作一个UIView并将所有内容放在其中,UIView应该会填满“UIViewController”的屏幕,拖动方法也应该很好:)祝你好运!(*您可能希望研究的另一个解决方案是制作一个包含嵌套在其中的所有对象的UIScrollView)制作一个UIView并将所有内容都放在其中,UIView应该填充“UIViewController”的屏幕,拖动方法也应该可以做到这一点:)祝您好运!(*您可能希望研究的另一个解决方案是创建包含嵌套在其中的所有对象的UIScrollView)
-(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);
}