user5175878
user5175878

Reputation:

Checking UIButton state for if condition

How can I check my button control state. I want to stop AVAudioplayer when the button is released.

Upvotes: 0

Views: 352

Answers (3)

zevij
zevij

Reputation: 2446

If I'm not mistaken you could use Control event TouchDown for press and TouchUpInside for release. Take a closer look at control events and implement the two methods you need.

Upvotes: 0

user5175878
user5175878

Reputation:

The problem is I want to stop avaudioplayer after releasing the button

Upvotes: 0

Kyle Redfearn
Kyle Redfearn

Reputation: 2281

You will need to add a target and a selector for a specified event. Typically that message gets sent to the view controller as follows:

button.addTarget(self, action: "someSelector", forControlEvents: .TouchUpInside)

You will need to implement the method someSelector in self, which is normally the containing view controller.

You can also do this in storyboard by creating an IBAction on your UIButton. When in the Assistant Editor, your storyboard or xib on one side, the view controller on the other, Ctrl+Click the button and drag over to the place you want to put the IBAction in your view controller.

Upvotes: 0

Related Questions