gpt4 book ai didi

ios - 覆盖 AVPlayerViewController 中的框架手势

转载 作者:可可西里 更新时间:2023-11-01 06:07:14 25 4
gpt4 key购买 nike

我希望能够在使用 AVKit 中的新 AVPlayerViewController 时更改播放控件的呈现方式。基本上,我想覆盖单指点击手势来做其他事情,并用双指点击替换该手势。我正在子类化 AVPlayerViewController 以添加此功能。

我可以通过创建一个新的 UITapGestureRecognizer 轻松地添加双指点击,但是通过单击这样做没有任何作用,因为播放控件仍然出现并且我的自定义手势方法没有被调用。我假设是因为 AVPlayerViewController 具有优先调用的手势。

我像往常一样设置手势...

// singleFingerTap: will never fire...
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleFingerTap:)];
singleFingerTap.numberOfTouchesRequired = 1;
singleFingerTap.delegate = self;
[self.view addGestureRecognizer:singleFingerTap];

// doubleFingerTap: will work correctly...
UITapGestureRecognizer *doubleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleFingerTap:)];
doubleFingerTap.numberOfTouchesRequired = 2;
doubleFingerTap.delegate = self;
[self.view addGestureRecognizer:doubleFingerTap];

关于如何在不访问私有(private)属性的情况下实现这一点有什么想法吗?它甚至被允许吗?我知道我可以用一个 AVPlayer 实例创建我自己的 View Controller ,然后创建我自己的播放控件,但我希望我可以在这里使用轻量级 AVKit 播放器并进行一些简单的修改。

我已经尝试遍历 AVPlayerViewController View 中的手势并删除它们,但 gestureRecognizers 属性为空。即使我能做到这一点,我也不知道如何添加回手势以在双指点击而不是单指点击时显示播放控件。

如有任何建议,我们将不胜感激!特别是这是否可能/是否允许。谢谢!


编辑:我找到了一种方法来显式取消阻止阻止我自己的手势的玩家的私有(private)手势。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
id firstGesture = gestureRecognizer;
id secondGesture = otherGestureRecognizer;

if ([firstGesture isKindOfClass:[UITapGestureRecognizer class]] && [secondGesture isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *tapGesture = firstGesture;
UITapGestureRecognizer *otherTapGesture = secondGesture;

if (tapGesture.numberOfTapsRequired == otherTapGesture.numberOfTapsRequired && tapGesture.numberOfTouches == otherTapGesture.numberOfTouches) {
// Disable the single tap that shows the playback controls...
return YES;
}
}
return NO;
}

这有效地阻止了播放控件出现在点击上,并且我的 singleTapGesture: 按预期触发。但是,我现在遇到了让播放控件出现在不同手势上的问题。 是否可以重新路由私有(private)手势,或以编程方式模拟私有(private)手势?

最佳答案

为什么不首先检查/修改目标/删除默认手势识别器?

您可以使用标准 UIViewgestureRecognizers 访问它们。


手势识别器可以隐藏在私有(private) subview 中。

另一种解决方案是将 userInteractionEnabled 设置为 NO 并将您的手势识别器添加到 super View 或“覆盖”透明 View 。

关于ios - 覆盖 AVPlayerViewController 中的框架手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25431215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com