initWithBarButtonItem 从 UIBarButtonSystemItemPause 更改为 UIBarButtonSystemItemPlay?
我的应用程序有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次都必须创建一个新按钮;你不应该在一个对象上调用 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).