2009-12-18 5 views
1

나는 음악 플레이어 응용 프로그램을 만드는 중이며 하나의 버튼에서 두 개의 작업을 호출해야합니다. 하나는 내부 이벤트를 터치하여 다음 트랙으로 건너 뛰고 다른 하나는 앞으로 앞으로 이동하여 '길게 누르십시오'. 나는이 긴 보도 자료를 가리키는 어떤 사건인지 모르겠다. 나는 그것이 아래로 만지라고 생각했지만, 버튼을 누르고있는 동안에 만 효과가 있었다. 내가 버튼을 놓았을 때, 그 트랙은 다음 아이템으로 건너 뛰었습니다. PLS, m 파일에서 방법을UIButton에 대한 두 가지 동작 방법. 다음 트랙과 앞으로 추구 :

AVAudioPlayer *appSoundPlayer;// declared in .h file 

도움 :

-(void)seekForwards{ 
NSTimeInterval timex; 
timex = appSoundPlayer.currentTime; 
     timex = timex+5; // forward 5 secs 

     appSoundPlayer.currentTime = timex; 
     timex = 0; 
} 

답변

4

는 개인적으로 그냥보기 컨트롤러 또는 버튼 서브 클래스 내에서 정수와 버튼의 상태를 추적 할 것입니다. 버튼의 동작을 추적하면 각 동작의 동작을 제어 할 수 있습니다. 이 물건의 일부에하는 .m 파일 던져에 다음

enum { 
    MyButtonScanning, 
    MyButtonStalling, 
    MyButtonIdle 
}; 



@interface YourClass : UIViewController { 
    NSInteger buttonModeAt; 
} 
@property (nonatomic) NSInteger buttonModeAt; 
-(IBAction)buttonPushedDown:(id)sender; 
-(void)tryScanForward:(id)sender; 
-(IBAction)buttonReleasedOutside:(id)sender; 
-(IBAction)buttonReleasedInside:(id)sender; 
@end 

를 실행 한 다음,이 같은 물건에 넣어 당신의 .H 파일에서 그 후

@implementation YourClass 
///in your .m file 
@synthesize buttonModeAt; 


///link this to your button's touch down 
-(IBAction)buttonPushedDown:(id)sender { 
    buttonModeAt = MyButtonStalling; 
    [self performSelector:@selector(tryScanForward:) withObject:nil afterDelay:1.0]; 
} 

-(void)tryScanForward:(id)sender { 
    if (buttonModeAt == MyButtonStalling) { 
     ///the button was not released so let's start scanning 
     buttonModeAt = MyButtonScanning; 

     ////your actual scanning code or a call to it can go here 
     [self startScanForward]; 
    } 
} 

////you will link this to the button's touch up outside 
-(IBAction)buttonReleasedOutside:(id)sender { 
    if (buttonModeAt == MyButtonScanning) { 
     ///they released the button and stopped scanning forward 
     [self stopScanForward]; 
    } else if (buttonModeAt == MyButtonStalling) { 
     ///they released the button before the delay period finished 
     ///but it was outside, so we do nothing 
    } 

    self.buttonModeAt = MyButtonIdle; 
} 

////you will link this to the button's touch up inside 
-(IBAction)buttonReleasedInside:(id)sender { 
    if (buttonModeAt == MyButtonScanning) { 
     ///they released the button and stopped scanning forward 
     [self stopScanForward]; 
    } else if (buttonModeAt == MyButtonStalling) { 
     ///they released the button before the delay period finished so we skip forward 
     [self skipForward]; 
    } 

    self.buttonModeAt = MyButtonIdle; 

} 

단지에있는 버튼의 동작을 연결 내가 IBactions 이전의 논평에서 언급했다. 나는 이것을 테스트하지는 않았지만 효과가있다.

+0

에이 타이머를 무효화하면 클래스에 넣고 빠른 버튼을 만들면 모든 것이 잘 작동하는 것 같습니다. . startScanForward, stopScanForward 및 skipForward 메소드를 추가하기 만하면됩니다. 답장을 보내 주셔서 감사합니다. – mjdth

+0

하지만 아무런 변화가 아직, 엄마 startScanForward 메서드에 문제가있을 수 있습니다, 나는 그만 멈추기 위해 무엇을 해야할지 모르겠다. 나는 ma qn에 ma startScanningForward 메소드를 추가하고 있는데, seekForwards라는 이름을 부여했다. – Nithin

+0

나는이 기능을 가진 간단한 uicontrolviewer를 만들었고 정상적으로 작동합니다. 이렇게하면 단추 자체가 건너 뛰기와 보유를 기반으로하는 탐색을 수행하는 방법에 대한 질문에 대한 대답이됩니다. 실제 파일 자체를 원하십니까? 아니면 스캔/스킵 코드에 문제가 있습니까? – mjdth

0

버튼의 클래스를 서브 클래스 화하고 UIResponder의 메소드를 사용하여 약간 재생할 수 있습니다. 예를 들어, touchesBegan 메서드에서 타이머를 호출하고 메서드를 호출하여 파일을 던지고 toucesEnded 메서드