2013-03-11 45 views
0

我想通過觸摸UIBarButtonItem並移動來創建滑動UIToolbar。我讀了一些話題,發現我必須實施touchesMoved。但是哪裏?只有我發現它是位於UIBarButtonItem中的UIButton。touchesMoved不適用於UIBarButtonItem

這是的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]; 

最奇怪在這一點,我想UIButton的結合動作(addTarget:動作:forEvents) 和它的作品,非常精確。但我不能接觸觸摸位置,因爲我沒有發生任何事件,所以我不能使用這種方法。

回答

1

您可以將UIPanGestureRecognizer添加到您的工具欄。

它只識別平移手勢(拖動)。在目標方法中,用CGRectContainsPoint(CGRect, point)方法和第一次觸摸如if(UIGestureRecognizerStateBegan)檢查觸摸是否在框架中。

如果是,則啓用拖動後UIGestureRecognizerStateEnded or UIGestureRecognizerStateCancelled 禁用拖動。

+0

謝謝,我不知道這種識別方法。 – skyylex 2013-03-11 16:41:57

相關問題