0
當用戶單擊UIButton1(rewind button)
時,需要更改其他UIButton2(playbutton)
的UIImage
。我怎樣才能做到這一點。單擊其他UIButton時更改UIButton的UIImage
UIButton *rewindButton = [UIButton buttonWithType:UIButtonTypeCustom];
[rewindButton addTarget:self action:@selector(rewind:) forControlEvents:UIControlEventTouchUpInside];
rewindButton.frame = CGRectMake(0, 0, 38, 38);
UIImage *imge = [UIImage imageNamed:@"Rewind Icon .png"];
[rewindButton setImage:imge forState:UIControlStateNormal];
UIBarButtonItem *rewind = [[UIBarButtonItem alloc] initWithCustomView:rewindButton];
-(void)rewind:(id)sender{
audioPlayer.currentTime = 0;
[timer invalidate];
ContainerViewController *viewController = [[[ContainerViewController alloc] init]autorelease];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
}
//Add Play Button
_playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_playButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
_playButton.frame = CGRectMake(0, 0, 38, 38);
[_playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateNormal];
[_playButton setImage:[UIImage imageNamed:@"52.png"] forState:UIControlStateSelected];
UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:self.playButton];
-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer:self.view.layer];
}else{
[sender setImage:[UIImage imageNamed:@"pause icon.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
[self resumeLayer:self.view.layer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}
}
}
當用戶點擊UIButton1(rewind button)
要求是其他UIButton2(play button)
的UIImage
從遊戲中的icon.png到pauseicon.png改變。
我該怎麼做。
任何想法。
我該如何讓播放按鈕執行以下步驟[audioPlayer play]; [self resumeTimer]; [self resumeLayer:self.view.layer];當倒帶按鈕改變播放按鈕的UIImage [_playButton setImage:[UIImage imageNamed:@「pause icon.png」] forState:UIControlStateNormal];這意味着當倒帶按鈕將播放按鈕的圖像更改爲暫停時,並且當用戶嘗試暫停播放按鈕時以及用戶恢復播放按鈕時,播放按鈕應執行以下步驟[audioPlayer play]; [self resumeTimer]; [self resumeLayer:self.view.layer]; – user1452248 2012-07-11 17:47:14
_playButton已經連接到執行這些步驟的playpauseAction:方法。您可以嘗試 - (void)倒帶:{[audioPlayer pause];而不是僅在回放中設置播放按鈕圖像。 audioPlayer.currentTime = 0; [self playpauseAction:_playButton]; // ...} – thelaws 2012-07-11 18:07:58