Tôi muốn hiển thị một số UIAlertController
ở trên cùng của UIViewController
với một bên là UICollectionView
. Quan điểm thu gom cần phải tập trung vào việc khởi động, vì vậy tôi overrode biến preferredFocusableView
như sau:Tiêu điểm biến mất khi mở UIAlertController trên tvOS 10 GM
override var preferredFocusedView: UIView? {
return self.collectionView
}
Với tvOS 9 tất cả hoạt động tốt: bộ điều khiển cảnh báo mở đúng và tôi đã có thể chọn một trong những UIAlertAction
s hiển thị.
Trên tvOS 10 Golden Master, sau khi mở bộ điều khiển cảnh báo và di chuyển đến một thao tác khác, tiêu điểm biến mất khỏi màn hình và tôi không thể cuộn đến các thao tác khác hoặc nhấn vào nút Menu của Siri Remote. Ứng dụng vẫn bị kẹt trong bộ điều khiển cảnh báo và tôi có thể nghe thấy âm thanh cuộn khi tôi cố di chuyển đến các tác vụ khác nhưng không có gì xảy ra trên màn hình. Tôi buộc phải thoát khỏi ứng dụng và mở lại nó.
Đây là mã của ứng dụng. Tôi đã cố gắng đặt preferredFocusableView
thành alertController.preferredFocusedView
hoặc bằng cách xóa phương pháp lấy nét của chế độ xem bộ sưu tập nhưng không có kết quả.
var alertController : UIAlertController?
func showAlert() {
alertController = UIAlertController(title:"Example title", message: "Example description", preferredStyle: .Alert)
let action1 = UIAlertAction(title: "Option 1", style: .Default) { (action : UIAlertAction) -> Void in
//call to another method
}
// action2, action3, action4...
let action5 = UIAlertAction(title: "Option 5", style: .Default) { (action : UIAlertAction) -> Void in
//call to another method
}
let actionDismiss = UIAlertAction(title: "Dismiss", style: .Destructive) { (action : UIAlertAction) -> Void in
self.alertController!.dismissViewControllerAnimated(true, completion: nil)
}
alertController!.addAction(action1)
alertController!.addAction(action2)
alertController!.addAction(action3)
alertController!.addAction(action4)
alertController!.addAction(action5)
alertController!.addAction(actionDismiss)
alertController!.preferredAction = action1
self.presentViewController(alertController!, animated: true, completion: nil)
}
override var preferredFocusedView: UIView? {
if self.alertController != nil {
return self.alertController!.preferredFocusedView
} else {
return self.collectionView
}
}
Bạn gọi 'showAlert' ở đâu? –
@DanielStorm khi người dùng chạm vào điều khiển từ xa trên nút bên trong trình điều khiển chế độ xem –
ưa thíchFocusedView không còn được dùng nữa trong tvOS10 https://developer.apple.com/reference/uikit/uifocusenvironment/1616830-preferredfocusedview –