简体   繁体   中英

How can I determine whether my UIButton's event is Touch Down?

How can I determine whether my button's event is Touch Down?

I want to do a function like this:

if(users click on touchdown event)
{

NSLog(@"a");

}

else if(users click on touchupinside event)
{

NSLog(@"b");
}

Eather you set two different IBAction methods in the InterfaceBuilder or you set two different targets via:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

in your code while creating the button.

You "find out" by letting the button tell you when the event happens.

Add a method (or methods) like this:

- (IBAction)myButtonClick:(id)sender;

In Interface Builder, attach the method(s) to the events you're interested in.

You create a separate method for each type of event if you want different behavior for a TouchDown as opposed to TouchUpInside.

您将每个唯一事件附加到其自己的IBAction

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