Ios 获取UIButton的x和y坐标
我有一个按钮叫“buttonPressed”。当我按下按钮时,我需要找到该按钮的x和y坐标。你有什么想法可以帮我吗Ios 获取UIButton的x和y坐标,ios,button,uibutton,tags,coordinates,Ios,Button,Uibutton,Tags,Coordinates,我有一个按钮叫“buttonPressed”。当我按下按钮时,我需要找到该按钮的x和y坐标。你有什么想法可以帮我吗 UIButton *circleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; circleButton.frame = rect; circleButton.layer.cornerRadius = 8.0f; [circleButton addTarget:self
UIButton *circleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
circleButton.frame = rect;
circleButton.layer.cornerRadius = 8.0f;
[circleButton addTarget:self
action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:circleButton];
-(void)buttonPressed:(id)sender
{
}
回答
- (IBAction)buttonPressed:(UIButton *)sender
{
CGPoint coordinates = sender.frame.origin;
CGFloat x = coordinates.x;
CGFloat y = coordinates.y;
}
听起来你想从动作的发送者那里得到X&Y。将sender参数附加到按钮点击方法,并找到sender的框架
- (IBAction)buttonTapped:(UIButton *)sender
{
CGPoint coordinates = sender.frame.origin;
}
哪个坐标?你想把它们送到哪里?谢谢。问题是:(UIButton*)我有(id)的地方。我没有看到这一教训