我创建了一个 UIButton *actionbtn,它的默认图像是 1.png,高亮图像是 2.png,我选择这个按钮,然后将它移动到屏幕的任何位置。我的代码是
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint touchMoved = [touch locationInView:self];
actionbtn.frame = CGRectMake(touchMoved.x-40, touchMoved.y-40, 80, 80);
}
如果我点击按钮并移动它,它不能移动,但是如果我触摸屏幕,并在屏幕上移动按钮可以工作...
最佳答案
试试这个:
这是一个带有在屏幕上移动的 UIButton 的示例...
关于ios - 如何移动 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6693868/