[英]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.