2013-03-11 3 views
0

UIBoolButtonItem을 터치하고 이동하여 슬라이딩 UIToolbar를 만들고 싶습니다. 몇 가지 주제를 읽고 touchesMoved를 구현해야한다는 것을 알았습니다. 그러나 어디에서? UIBarButtonItem에있는 UIButton을 발견 한 곳입니다. (: 조치 : forEvents addTarget을) 그리고 그것은 매우 정확한, 작품의 touchesMoved가 UIBarButtonItem에 대해 작동하지 않습니다.

내가 행동에있는 UIButton을 결합하려고하는 것이이에서의 ViewController 의 viewDidLoad

self.toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(bounds.origin.x, bounds.size.height - 2.5*height, bounds.size.width, 2*height)]; 

SlideButton* infoButton = [SlideButton buttonWithType: UIButtonTypeDetailDisclosure]; 
UIBarButtonItem *slideButton = [[UIBarButtonItem alloc]initWithCustomView:infoButton]; 

self.toolbar.items = items; 
[self.view addSubview:self.toolbar]; 

대부분의 이상하다. 그러나 나는 어떤 사건도 발생하지 않기 때문에 접촉의 위치를 ​​취할 수 없으므로이 접근법을 사용할 수 없습니다.

답변

1

도구 모음에 UIPanGestureRecognizer을 추가 할 수 있습니다.

팬 제스쳐 (끌기) 만 인식합니다. 대상 메서드에서 CGRectContainsPoint(CGRect, point) 메서드로 바 버튼의 프레임에 터치가 있는지 확인하고 if(UIGestureRecognizerStateBegan)과 같이 먼저 터치합니다.

그렇다면 UIGestureRecognizerStateEnded or UIGestureRecognizerStateCancelled 끌기 사용 중지 후 끌기를 사용하십시오.

+0

감사합니다.이 인식 방법에 대해 알지 못합니다. – skyylex

관련 문제