变换(旋转)UIBarButtonItem

发布于 2024-09-26 07:46:14 字数 447 浏览 5 评论 0原文

有人知道如何转换 UIBarButtonItem 吗?

我尝试了这个但没有结果:( 它不适用于 UIBarButtonItem 及其自定义视图。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0f];
CGAffineTransform myTransform = CGAffineTransformMakeRotation(M_PI_2);
UIBarButtonItem * currentItem =  [self.toolbarItems objectAtIndex:4];
currentItem.customView.transform = myTransform;
[UIView commitAnimations];

我确认转换适用于其他视图(我尝试使用 self.view)。

谢谢 !

Does anybody know how to transform a UIBarButtonItem ?

I tried this but with no results :(
It's not working on both UIBarButtonItem and its customview.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0f];
CGAffineTransform myTransform = CGAffineTransformMakeRotation(M_PI_2);
UIBarButtonItem * currentItem =  [self.toolbarItems objectAtIndex:4];
currentItem.customView.transform = myTransform;
[UIView commitAnimations];

I confirm the transform works on other views (I tried with self.view).

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黯淡〆 2024-10-03 07:46:14

使用:

UIView *view = [backItem valueForKey:@"view"];
view.transform = CGAffineTransformMakeScale(-1, 1);

use:

UIView *view = [backItem valueForKey:@"view"];
view.transform = CGAffineTransformMakeScale(-1, 1);
星星的轨迹 2024-10-03 07:46:14

UIBarButtonItem 不扩展 UIView,因此无法直接转换。您可以将要转换的 UIBarButtonItem 添加到 UIToolbar,转换 UIToolbar,然后将工具栏作为自定义视图添加到另一个 UIBarButtonItem。然后可以将此项目设置为导航项目或添加到另一个 UIToolbar。

UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(handleForwardItemTouch:)];

UIToolbar *backToolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 44, 44)] autorelease];
[backToolbar setTransform:CGAffineTransformMakeScale(-1, 1)];

UIBarButtonItem *backToolbarItem = [[[UIBarButtonItem alloc] initWithCustomView:backToolbar] autorelease];
self.navigationItem.rightBarButtonItem = backToolbarItem;

UIBarButtonItem does not extend UIView, so it cannot be transformed directly. You can add the UIBarButtonItem you wish to transform to a UIToolbar, transform the UIToolbar and then add the toolbar as a custom view to another UIBarButtonItem. This item can then be set as a navigation item or added to another UIToolbar.

UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(handleForwardItemTouch:)];

UIToolbar *backToolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 44, 44)] autorelease];
[backToolbar setTransform:CGAffineTransformMakeScale(-1, 1)];

UIBarButtonItem *backToolbarItem = [[[UIBarButtonItem alloc] initWithCustomView:backToolbar] autorelease];
self.navigationItem.rightBarButtonItem = backToolbarItem;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文