0

以编程方式将 rewindButton 与 playButton 连接起来。rewindButton 只是从头开始倒带和播放,playButton 从播放切换到暂停。在 rewindButton 方法中使用语句来更改 UIButton2 的 UIImage 时按下 UIButton1。那工作正常。

按下并暂停播放按钮时,PlayButton 方法工作正常。即使在恢复后也可以正常工作。

问题简报:

当按下 rewindButton 时,它会将 playButton 的 UIImage 更改为 PauseImage,以便用户可以暂停。恢复暂停时出现问题。When pause is resumed it is reloading view controllers.它应该只根据代码第一次加载视图控制器。

-(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];
[audioPlayer play];
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                    target:self
                                    selector:@selector(displayviewsAction:)
                                    userInfo:nil
                                    repeats:NO];
    [_playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];   
 }



-(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.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;
    } 
    } 
    }

- (void)displayviewsAction:(id)sender
{  

 First *first = [[First alloc] init];
 first.view.frame = CGRectMake(0, 0, 320, 425);
 CATransition *transitionAnimation = [CATransition animation];   
 [transitionAnimation setDuration:1];
 [transitionAnimation setType:kCATransitionFade];    
 [transitionAnimation setTimingFunction:[CAMediaTimingFunction     functionWithName:kCAMediaTimingFunctionEaseIn]];    
 [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];   
   [self.view addSubview:first.view];
 [first release];   
 self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];     
 }

-(void)Second 
{
Second *second = [[Second alloc] init];
second.view.frame = CGRectMake(0, 0, 320, 425);
CATransition *transitionAnimation = [CATransition animation];
[transitionAnimation setDuration:1]; 
[transitionAnimation setType:kCATransitionReveal];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];
[self.view addSubview:second.view]; 
[second release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];
}
4

1 回答 1

0

在 rewind 方法中恢复原因后重新加载视图控制器的原因我忘记添加 isFirstTime == YES 来加载视图控制器。视图控制器不需要重新加载。视图控制器仅在第一次时才需要从头开始加载。

因此,在 rewind 方法中设置 isFirstTime == YES 的值后,它不会在从暂停中恢复后从头开始重新加载视图控制器。

-(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];
[audioPlayer play];
if(isFirstTime == YES){
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                target:self
                                selector:@selector(displayviewsAction:)
                                userInfo:nil
                                repeats:NO];
 isFirstTime  = NO;
}

[_playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];   
 }

现在它工作正常。

于 2012-07-14T15:00:33.063 回答