我从Two action methods for an UIButton; next track and seek forward:
更改它根据您的要求了。
就我个人而言,我只是用你的视图控制器或按钮子类中的整数跟踪按钮的状态。如果你跟踪按钮的功能,你可以控制每个动作的作用。在把一些东西,这样你的.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行动的评论中注意到了。我没有测试过,但它应该可以工作。
只是一个猜测,做一个BOOL和两个方法检查,并通过翻转动作:' - (空) removeTarget:action:' – 2013-03-23 15:44:24
您是否也希望发生相反的情况 - 也就是说,如果touchDown被触发,您是否需要dragInside不会在用户开始拖动时发生?做这项工作的唯一方法是在开始时稍微延迟一段时间,看看是否有阻力开始。如果这是不可接受的,那么你将不得不采用不同的设计。 – rdelmar 2013-03-23 17:09:31