English 中文(简体)
Rotating buttons on UIToolBar in an iPhone app
原标题:

Is there any way to rotate the buttons on a UIToolBar as the camera application does when you take a picture in landscape?

When the user rotates the iPhone I want to keep the toolbar on the same place and rotate the buttons so they don t stand sideways.

thanks in advance!

最佳回答

I don t believe there s anything built-in to handle this for you. However, it s definitely possible to code this. 1) Listen for the message telling you the orientation is changing. Don t allow the view to rotate (this will keep your toolbar from moving), but use the opportunity to do other stuff.
2) Replace the images in the buttons with images rotated 90 degrees in whichever direction is appropriate.
3) Do the image replacement within the context of a Core Animation which performs a rotation animation. You should be able to find some code samples for how to do this.

Hope that helps you look in the right direction.

问题回答

i had to do this too. doing replace-the-image like Ken suggested, i couldn t find a good way to animate the rotation. it s best to be able to set the transform on the item s image, which you can t do to a simple UIBarButtonItem but you can with one built with a custom view:

in place of [[UIBarButtonItem alloc] initWithImage:image target:t action:a] :

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:t action:a forControlEvents:UIControlEventTouchUpInside];
[button setImage:image forState:UIControlStateNormal];
button.showsTouchWhenHighlighted = YES; // makes it highlight like normal
item = [[UIBarButtonItem alloc] initWithCustomView:button];

then you can do:

[UIView beginAnimations:@"rotate barbuttonitems" context:NULL];
item.customView.transform = CGAffineTransformMakeRotation(M_PI_2);
[UIView commitAnimations];




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签