個人而言,我只希望跟蹤與您的視圖控制器或按鈕子內的整按鈕的狀態。如果你跟蹤按鈕的功能,你可以控制每個動作的作用。在把一些東西,這樣你的.h文件中:
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
,然後在.m文件扔在一些這方面的東西:
@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;
}
之後只是鏈接按鈕的行動,我已經在IB行動的評論中注意到了。我沒有測試過,但它應該可以工作。
無效此計時器只是把它放到一個類,併爲它做了一個快速按鈕,似乎一切工作正常。您只需添加startScanForward,stopScanForward和skipForward方法。 – mjdth 2009-12-18 07:16:06
感謝您的回覆。但沒有變化,可能是與馬startScanForward方法的問題,我不知道該怎麼做停止停止。我將ma startScanningForward方法添加到ma qn中,我給了名稱seekForwards:給它。 – Nithin 2009-12-18 09:12:49
我用這些函數創建了一個簡單的uicontrolviewer,它工作正常。這將回答你的問題,如何讓按鈕本身做基於持有的跳過和尋找。你想自己的實際文件?或者你的掃描/跳過代碼有問題? – mjdth 2009-12-18 09:17:23