Reputation: 815
I want to create sliding UIToolbar by touching the UIBarButtonItem on it and moving. I read some topics, and found that I must implement touchesMoved. But where? Only place that I found it's UIButton which I located in UIBarButtonItem.
This is 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];
Most strange in this, that I tried to bind UIButton to action (addTarget:action:forEvents) And it's works, very exact. But I can't take position of touch, because I have no event that occured, so I can't use this approach.
Upvotes: 0
Views: 118
Reputation: 6065
You can add a UIPanGestureRecognizer
to your toolbar.
It recognize only pan gestures(drag). In target method check if touch is in frame of you bar button with CGRectContainsPoint(CGRect, point)
method and first touch like if(UIGestureRecognizerStateBegan)
.
if yes then enable dragging after UIGestureRecognizerStateEnded or
UIGestureRecognizerStateCancelled
disable dragging.
Upvotes: 1