简体   繁体   English

触摸时显示视图控制器

[英]Present view controller while touching

I want to implement a hold-to-preview button that brings up a view containing an AVPlayerLayer , which plays as long as the touch doesn't end. 我想实现一个保持预览的按钮,该按钮调出一个包含AVPlayerLayer的视图,只要触摸不结束,该视图就会播放。 The video player is contained in a different view controller, and I am hoping to be able to use presentViewController:animated: when presenting it, and not just add it as a subview and child view controller. 视频播放器包含在其他视图控制器中,我希望能够在演示时使用presentViewController:animated:而不仅仅是将其添加为子视图和子视图控制器。

My question is about how to deal with the touch event. 我的问题是关于如何处理触摸事件。 I see two possible ways: 我看到两种可能的方式:

  • I try to transfer the active touch down event to the presented view controller (not sure if even possible), or 我尝试将活动的触地事件转移到显示的视图控制器(甚至不确定)。或者
  • I try to keep the original view controller's gesture recognizer active, and then let the video view controller know when it's time to dismiss itself. 我尝试保持原始视图控制器的手势识别器处于活动状态,然后让视频视图控制器知道何时该自行关闭。 I'm hoping this could be achieved either by just setting the presented view controller's userInteractionEnabled to false, or perhaps using a UIViewControllerTransitioningDelegate to present it, and then just skip calling completeTransition: or something similar (I believe touches don't register on the new view until you complete the animation, but please correct me if I'm wrong). 我希望可以通过将呈现的视图控制器的userInteractionEnabled设置为false来实现,或者使用UIViewControllerTransitioningDelegate呈现它,然后跳过调用completeTransition:或类似的操作(我相信触摸不会在新的注册)查看,直到完成动画为止,但如果我错了,请纠正我)。

My question is about how to deal with the touch event. 我的问题是关于如何处理触摸事件。

Touches are always associated with the view that they start in. You can't transfer the touch to a different view. 触摸始终与它们开始的视图相关联。您无法将触摸转移到其他视图。 I've never tried it, but the options I think you should explore first are: 我从未尝试过,但是我认为您首先应该探索的选择是:

  • Use view controller containment. 使用视图控制器遏制。 Make your preview view controller a child view controller of the one where the touch originates. 使您的预览视图控制器成为触摸起源的子视图控制器。 That way the parent and its view hierarchy never go away, although they could be covered up. 这样,父级及其视图层次结构就不会消失,尽管它们可能会被掩盖。

  • Attach the gesture recognizer to the window. 将手势识别器连接到窗口。 A window is a view, and should be able to have gesture recognizers. 窗口是一个视图,应该能够有手势识别器。 You could make the gesture recognizer's target the app delegate or some other object that will always be around, and have the delegate post a notification when the recognizer is triggered. 您可以将手势识别器作为应用程序委托或永远存在的其他对象的目标,并在触发识别器时让委托发布通知。 Again, I haven't tried this, but it seems like it should work. 同样,我还没有尝试过,但似乎应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM