简体   繁体   中英

Setting custom target and action in Interface Builder

I have a custom control that is reused frequently. It is meant to respond to a long press. I'd like to be able to set the target and selector in interface builder. Is there any method for having something like-

@property (nonatomic,assign) IBOutlet SEL longPressSelector;

Alternatively is there a way to add custom UIControlEvents that can be set it Interface Builder?

Thanks

I think you can use

-(void)touchesBegan:(NSSet*)touches  withEvent:(UIEvent*)event

to start a NSTimer which will count time for you

and

-(void)touchesEnded:(NSSet*)touches  withEvent:(UIEvent*)event

to stop that timer and will get for how much time user tapped a view and then you can do an event according to that time for long press.

Hope, it'll help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM