开发者

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 开发者_如何学Pythonper 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


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜