У меня есть новый жест (коснитесь, перетащите на другой, отпустите), который я хотел бы, чтобы он вел себя так же, как touchUpInside или touchDown или любой из этого списка, который появляется, когда вы связываете IBActions в конструкторе интерфейса. (Т.е. я хочу, чтобы мои пользовательские были в этом списке, чтобы я мог связать их с IBActions)
Есть ли способ сделать это или мне нужно программно связать вещи вместе?
Обновление: следующая лучшая вещь
Вот очень урезанная версия того, что я сделал, чтобы отделить мой объект от любого другого конкретного класса, на случай, если кто-то еще попытается это сделать:
@interface PopupButton : UIView {
}
//These are the replacement "IBAction" type connections.
@property (nonatomic) SEL tapAction;
@property (nonatomic, assign) id tapTarget;
@property (nonatomic) SEL dragAction;
@property (nonatomic, assign) id dragTarget;
@end
@implementation PopupButton
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//Your custom code to detect the event
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//Your custom code to detect the event
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//Here we'll say I detected the event I called "drag".
if (!(self.dragTarget && self.dragAction)) {
NSLog(@"No target for drag.");
abort();
} else {
[self.dragTarget performSelector:self.dragAction];
}
//And here I detected the event "tap".
if (!(self.tapTarget && self.tapAction)) {
NSLog(@"No target for single tap.");
abort();
} else {
[self.tapTarget performSelector:self.tapAction];
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
//Your custom code to detect the event
}
@end
Теперь, чтобы настроить это, в контроллере представления я хотел связать эти действия, вместо этого я поставил это:
- (void)viewDidLoad
{
[equalsPopupButton setTapTarget:self];
[equalsPopupButton setTapAction:@selector(equalsPress)];
[equalsPopupButton setDragTarget:self];
[equalsPopupButton setDragAction:@selector(isNamingResult)];
}
Очевидно, не так элегантно, как опция + перетаскивание, но он выполняет свою работу, не делая мой код жестким и привязанным. Надеюсь, это поможет кому-то.