2016-09-09 17 views
5

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ó.

enter image description here enter image description here

Đâ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 
    } 
} 
+0

Bạn gọi 'showAlert' ở đâu? –

+0

@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 –

+0

ưa thíchFocusedView không còn được dùng nữa trong tvOS10 https://developer.apple.com/reference/uikit/uifocusenvironment/1616830-preferredfocusedview –

Trả lời

4

Apple chỉ replied to radar của tôi:

Bên đính kèm ứng dụng, bạn đang ghi đè chức năng của UIScrollView trong phần mở rộng để trả lại true cho canBecomeFocused(), đó là nguyên nhân của các hiệu ứng bất ngờ này . Tiêu điểm dường như biến mất khi chuyển sang tùy chọn UIAlertController thứ hai; tuy nhiên, nó thực sự chuyển tiêu điểm sang chế độ xem cuộn được bao quanh các thành phần khác nhau của UIAlertController, vì điều này hiện được phép do phần mở rộng được đề cập ở trên.

Để giải quyết điều này, tạo một lớp con tùy chỉnh của UIScrollView được sử dụng chỉ trong trường hợp canBecomeFocused() phải trả lại true.

1

Bạn đang ghi đè toàn bộ công cụ tập trung của hệ thống. Hãy thử điều này:

// MARK: - Update Focus Helper 
var viewToFocus: UIView? = nil { 
    didSet { 
     if viewToFocus != nil { 
      self.setNeedsFocusUpdate() 
      self.updateFocusIfNeeded() 
     } 
    } 
} 

override weak var preferredFocusedView: UIView? { 
    if viewToFocus != nil { 
     return viewToFocus 
    } else { 
     return super.preferredFocusedView 
    } 
} 

Sau đó thiết lập cảnh báo của bạn như là xem khi bạn muốn tập trung để thay đổi nó:

viewToFocus = someView 
+0

Vẫn không hoạt động :(Tôi ' m đặt tiêu điểm sau khi trình bày của UIAlertController Hai phương thức hoạt động chính xác nhưng tiêu điểm vẫn biến mất. –

Các vấn đề liên quan