제스처 인식기를 제 단추에 추가하여 사용자가 단추 프레임을 스 와이프 한 경우 코드를 실행할 수 있습니다. 스 와이프가 위로, 오른쪽, 왼쪽 또는 아래쪽으로 있으면이 코드가 달라지기를 바랍니다.UIGestureRecognizer를 어떻게 초기화합니까?
-(void)viewDidLoad
{
[super viewDidLoad];
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(0, 0, 100, 100);
[self.view addSubview:button];
UIGestureRecognizer *swipe=[[UIGestureRecognizer alloc]initWithTarget:button action:@selector(detectSwipe)];
[button addGestureRecognizer:swipe];
}
그래서 initWithTarget:action:
일이 올바 릅니까? 이제 어떻게할까요? detectSwipe
메서드를 구현하는 방법은 무엇입니까?
다음은 제스처 인식기의 대상을 제외한 모든 권리를 가지고 detectSwipe
-(IBAction)detectSwipe:(UIButton *)sender
{
/* I dont know how to put this in code but i would need something like,
if (the swipe direction is forward and the swipe is > sender.frame){
[self ForwardSwipeMethod];
} else if //same thing for right
else if //same thing for left
else if //same thing for down
}
detectSwipe : 보낸 사람으로 버튼을하지 않는
@selector(detectSwipe:)
콜론은 ":"당신의 방법은 인수를 가지고 있기 때문이다. 인수로 전달되는 제스처 인식기입니다. 또는 인식기가 감지 한 동작과 제스처를 알 수있는 다른 방법은 무엇입니까? –