在我的应用程序中,我需要在圆形边框内移动一个uibutton,我尝试了以下代码,但它似乎没有工作 -
- (IBAction) imageMoved:(id) sender withEvent:(UIEvent *) event{
UIControl *control = sender;
UITouch *t = [[event allTouches] anyObject];
CGPoint pPrev = [t previousLocationInView:control];
CGPoint p = [t locationInView:control];
if (control.center.x>40&&control.center.x<300) {
CGPoint center = control.center;
center.x += p.x - pPrev.x;
center.y += p.y - pPrev.y;
control.center = center;
}else if (control.center.y>40&&control.center.y<320){
CGPoint center = control.center;
center.x += p.x - pPrev.x;
center.y += p.y - pPrev.y;
control.center = center;
}else{
}
}
有谁知道如何做到这一点?提前致谢。