0

I made a vertical (in looks) toolbar programmatically. Using initWithFrame I set the width and height of the toolbar and sent it to extreme right.

Now I added a bar button item to the toolbar and set an action for it. But when I click anywhere on the toolbar, the action message is being sent. And I checked the sender, the sender is not the toolbar but the button.

I tried on another toolbar which I placed horizontally, the buttons are seen as tapped if I click in the vicinity of the button. And since now my toolber is vertical (but horizontal according to iOS), clicking anywhere on the toolbar calls the function.

I want to send the message only when I click on the button and not on the toolbar.

I want to use the camera icon provided by apple, so I am not in favor of using UIButton. (I can set a custom image, but it would be good if i can avoid that) I also think that placing a horizontal toolbar and using CGAffineTransform can solve the problem. But it would be nice if there is clean method.

neeraj
  • 1,191
  • 4
  • 19
  • 47

2 Answers2

1

Using the transform is definitely the way to go.

Run the identity transform through this function and set it as the transform on your bar. I think it is a very simple solution.

It shouldn't be hard to set the transform right after you init with a normal frame. To avoid stretching you can make that frame using the values you are already using but swapping the x and y.

JoshRagem
  • 575
  • 3
  • 10
  • Thanks. Itried rotaion, but it also rotated the toolbar button with it. So I decided to use custom button instead. By the way, do you know how can I disable touch on toolbar but keep the touch on the toolbar items enabled? because even in the horizontal toolbar, clicking near the buttons starts up the action – neeraj Sep 13 '12 at 07:31
  • 1
    I don't, but it might just be the os thinking you meant to hit the button--remember that these apps are used with thumbs, so a tap even is larger than a click. If you want to rotate the button, you can use a transform on it as well. Just use the opposite angle as you used on the toolbar to turn it back straight. – JoshRagem Sep 13 '12 at 13:28
0

I don't believe that UIToolbar supports vertical orientation; you'll probably be better off rolling your own toolbar-like control.

Caleb
  • 124,013
  • 19
  • 183
  • 272