检测 MPVolumeView 中的触摸

发布于 2024-10-15 19:49:55 字数 385 浏览 8 评论 0原文

我正在使用 AVPlayer 复制 MPMediaPlayerView,以便我可以向其添加一些功能。我创建了一个具有播放/暂停功能的 UIView,并在触摸时显示它,然后根据 HeadsUpUI 示例代码设置一个计时器来隐藏它。我向其中添加了 MPVolumeView 来调整音量。

这工作得很好,除了如果你滑动音量时,我的父视图不知道你仍在与子视图交互,并在计时器触发时隐藏自己。所以你仍在调整音量,但滑块已不再存在。

我最想知道的是视图和所有子视图上的触摸何时结束。有办法做到这一点吗?

我能想到的唯一解决方案是遍历 MPVolumeView 的子视图,当我找到滑块时,观察跟踪属性以了解其何时完成跟踪。但这并不能解决有人长时间按住按钮的情况。我真的很想找到一个通用的解决方案。

TIA

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2024-10-22 19:49:55

将手势识别器添加到 MPVolumeView。让手势识别器调用您视图中的方法来重置计时器。

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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文