initWithBarButtonItem 从 UIBarButtonSystemItemPause 更改为 UIBarButtonSystemItemPlay?

发布于 2024-08-20 18:20:45 字数 639 浏览 3 评论 0原文

我的应用程序有一个 UIBarButtonItem,在 UINavigationBar 屏幕的右上角有一个 UIBarButtonItemPause 图标。我希望拥有它,以便当我按下按钮时,它会将图标更改为播放按钮,并在取消暂停时返回到暂停按钮(类似于 iTunes、Quicktime 或 iPhone 的集成媒体播放器的方式)当按下播放/暂停按钮时,我是否可以只更改图标,或者是否需要每次创建一个新按钮并将其放在栏上才能发生这种情况?该按钮可以在这里找到:

- (IBAction)pauseapp:(UIBarButtonItem *)sender
{
 if(paused==TRUE)
 {
  paused=FALSE;
  [pause initWithBarButtonSystemItem:(UIBarButtonSystemItemPause) target:self action:NULL];
  return;
 }
 else if(paused==FALSE)
 {
  paused=TRUE;
  [pause initWithBarButtonSystemItem:(UIBarButtonSystemItemPlay) target:self action:NULL];
  return;
 }

My application has a UIBarButtonItem with a UIBarButtonItemPause icon in the upper right corner of the screen on a UINavigationBar. I'm looking to have it so that when I press the button it changes the icon to a play button, and back to a pause button when it is unpaused (similar to the way in which iTunes, Quicktime, or iPhone's integrated media player does when pressing the play/pause button. Is it possible for me to just change the icon or would it be necessary to create a new button each time and place it on the bar for that to happen? The code that is triggered by the pressing of the button can be found here:

- (IBAction)pauseapp:(UIBarButtonItem *)sender
{
 if(paused==TRUE)
 {
  paused=FALSE;
  [pause initWithBarButtonSystemItem:(UIBarButtonSystemItemPause) target:self action:NULL];
  return;
 }
 else if(paused==FALSE)
 {
  paused=TRUE;
  [pause initWithBarButtonSystemItem:(UIBarButtonSystemItemPlay) target:self action:NULL];
  return;
 }

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

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

发布评论

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

评论(1

背叛残局 2024-08-27 18:20:45

每次都必须创建一个新按钮;你不应该在一个对象上调用 initXXX 多次(在分配之后)。

You have to create a new button each time; you should never call initXXX on an object more than one time (right after alloc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文