2012-09-25 3 views
-4

"buttonPressed"버튼이 있습니다. 버튼을 누르면 x와 y 좌표를 해당 버튼으로 찾아야합니다. 나를 도울 수있는 아이디어가 있습니까? 당신은 행동의 보낸 사람 떨어져 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; 
    } 
+0

? 어디로 보내시겠습니까? – wattson12

+0

@ wattson12 괜찮습니다. 해결했습니다 –

답변

5

는 소리. 단추 매개 변수에 보낸 사람 매개 변수를 연결하고 보낸 사람의 프레임을 찾습니다.

- (IBAction)buttonTapped:(UIButton *)sender 
{ 
    CGPoint coordinates = sender.frame.origin; 
} 
+1

고마워요. 문제는 (UIButton *) (id)가있는 곳입니다. 나는 그것을 보지 못했다 :/배운 교훈 –

관련 문제