-4
我有一个名为“buttonPressed”的按钮。当我按下按钮时,我需要找到该按钮的x和y坐标。你有什么想法可以帮助我吗?获取UIButton的x和y坐标
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;
}
哪个坐标?你想在哪里发送? – wattson12
@ wattson12没关系,解决了 –