1

Is it possible to have a UIGestureRecognizer detect a vertical swipe and adjust the volume from my app.

So if the user swipes vertical up, the volume increases, and if the user swipes down, the volume decreases.

My code for playing the audio :

AppDelegate *appDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.countSound == 1) {
    // OFF
    appDelegate.backgroundMusic.volume = appDelegate.countSound;
    appDelegate.countSound = 0;
}
else
{
    // ON
    appDelegate.backgroundMusic.volume = appDelegate.countSound;
    appDelegate.countSound = 1;
}

Any code would be highly appreciated,

Cheers Joe.

coderjoe
  • 137
  • 2
  • 16
  • Add a UIPanGestureRecognizer to your view. here's an example http://stackoverflow.com/questions/6672677/how-to-use-uipangesturerecognizer-to-move-object-iphone-ipad – Adrian Ancuta Feb 28 '12 at 09:39
  • One trick could be use simple swipe gesture with your control view and then make rotation transform of 90 degrees for that control view. – Ravin Feb 28 '12 at 09:45

1 Answers1

1

Add this in view did load...

- (void)viewDidLoad {
    UISwipeGestureRecognizer *recognizer;



    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUp:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release];

    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeDown:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release];


    [super viewDidLoad];
}

and then in respective selectors increase or decrease the volume..

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115