简体   繁体   English

关闭呈现的视图控制器时如何恢复焦点?

[英]How to restore focus when presented view controller is dismissed?

I am building an app like Photos where you can scroll through thumbnails of your photos in a UICollectionView and you can tap on one to view that photo full-screen.我正在构建一个像照片这样的应用程序,您可以在其中滚动UICollectionView照片的缩略图,您可以点击其中一个以全屏查看该照片。 I'm working to add support for keyboard navigation so you can focus on a photo with the arrow keys then press space to view it full-screen, dismiss it, then focus on another photo.我正在努力添加对键盘导航的支持,以便您可以使用箭头键专注于照片,然后按空格键以全屏查看,关闭它,然后专注于另一张照片。 This works well in the Photos app, but in my app when you dismiss the full-screen view controller, the focus is not restored - that cell is not focused until you press an arrow key again.这在照片应用程序中运行良好,但在我的应用程序中,当您关闭全屏视图控制器时,焦点不会恢复 - 在您再次按下箭头键之前,该单元格不会被聚焦。 How do you restore the focus when the presented view controller is dismissed?当呈现的视图控制器被关闭时,如何恢复焦点?

To enable focus I set these in the UICollectionViewController :为了启用焦点,我在UICollectionViewController设置了这些:

collectionView.allowsFocus = true
collectionView.allowsFocusDuringEditing = true
collectionView.remembersLastFocusedIndexPath = true

I thought setting this would do the trick but I get the same behavior:我认为设置它可以解决问题,但我得到了相同的行为:

restoresFocusAfterTransition = true

After a lot of debugging, I determined this was not working because I overrode canBecomeFirstResponder returning true .经过大量调试后,我确定这不起作用,因为我覆盖了返回true canBecomeFirstResponder Once I returned false in both the presenting and presented view controller, focus properly restored to the presenting upon dismissing the presented.一旦我在呈现和呈现的视图控制器中都返回false ,则在关闭呈现时将焦点正确恢复到呈现。 I am not sure if this is intentional behavior so I filed a bug report FB9814702.我不确定这是否是故意行为,所以我提交了错误报告 FB9814702。

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

相关问题 当通过手势关闭呈现的视图 controller 时如何获得通知? - How to get notified when a presented view controller is dismissed with a gesture? 检测何时关闭呈现的视图控制器 - Detect when a presented view controller is dismissed 模态显示/关闭视图控制器时通知? - Notification when view controller is presented modally/dismissed? 调用viewWillAppear时显示视图控制器的问题被解除 - Issue with calling viewWillAppear of presenting view controller when presented one is dismissed 为什么简单的模态视图控制器在显示和关闭时会滞后? - Why would a simple modal view controller lag when presented and dismissed? TabBarController viewDidAppear 在呈现的视图控制器关闭时未调用 - TabBarController viewDidAppear not called when presented view controller dismissed 从主视图控制器知道何时解散了所提供的模态视图控制器? - Knowing from the main view controller when the presented modal view controller is dismissed? iOS /自动版式:取消已演示的控制器后,更改为演示视图 - IOS/Autolayout: Change to Presenting View After Presented Controller Dismissed 所有呈现的视图控制器都不会被解雇 - All the presented view controllers are not dismissed 模态视图控制器被关闭后如何调用函数 - How to call a function when a Modal View Controller has been dismissed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM