Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting touches in MPVolumeView

I'm replicating an MPMediaPlayerView using AVPlayer so I can add some functionality to it. I've created an UIView with play/pause and I display it on a touch and then set a timer to hide it as per the HeadsUpUI sample code. I've added a MPVolumeView to it to adjust the volume.

That works fine, except that if you're sliding the volume around, my parent view has no idea you are still interacting with a subview and hides itself when the timer fires. So you're still adjusting the volume, but the slider is no longer there.

What I'd ideally like to know is when the touch has ended on the view and all subviews. Is there a way to do this?

The only solution I can think of is to walk the subviews of MPVolumeView and when I find the slider, observe the tracking property to know when it is done tracking. But that doesn't handle someone hold downing on a button for a long time. I'd really like to find a general solution to this.

TIA

like image 441
Mark Lilback Avatar asked Feb 06 '11 00:02

Mark Lilback


1 Answers

Add a gesture recognizer to the MPVolumeView. Have the gesture recognizer call a method in your view that resets the timer.

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(0, 88, 320, 30)];
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(volumeAdjusted:)];
recognizer.cancelsTouchesInView = NO;     // this line is VERY important
[volumeView addGestureRecognizer:recognizer];
[self.view addSubview:volumeView];
[volumeView release];

-(void)volumeAdjusted:(UIGestureRecognizer *)recognizer {
     // reset timer
}
like image 148
Drew C Avatar answered Sep 28 '22 21:09

Drew C