微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – 在tvOS 10 GM上打开UIAlertController时焦点消失了

我想在UIViewController上面显示一个UIAlertController,里面有一个UICollectionView.集合视图需要专注于启动,所以我覆盖了preferredFocusableView变量,如下所示:

override var preferredFocusedView: UIView? {
    return self.collectionView
}

使用tvOS 9一切正常:警报控制器正常打开,我可以选择其中一个显示的UIAlertActions.

在tvOS 10 Golden Master上,打开警报控制器并滚动到另一个动作后,焦点从屏幕上消失,我无法滚动到其他操作或点击Siri遥控器的菜单按钮.该应用程序仍然卡在警报控制器中,当我尝试滚动到其他操作但屏幕上没有任何操作时,我可以听到滚动声音.我必须强制退出应用程序并重新打开它.

enter image description here


enter image description here

这是应用程序的代码.我尝试将preferredFocusableView设置为alertController.preferredFocusedView,或者删除集合视图的焦点方法但没有结果.

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
    }
}

解决方法

Apple只是回复了我的雷达:

Inside the attached application,you’re overwriting the functionality
of UIScrollView in an extension to return true for
canBecomeFocused(),which is the cause of these unexpected side
effects. The focus seems to be disappearing when moving to a second
UIAlertController option; however,it is actually transferring focus
to the scroll view wrapped around the varIoUs components of the
UIAlertController,since this is Now allowed due to the extension
mentioned above.

To solve this,create a custom subclass of UIScrollView to be used
only in the instances where canBecomeFocused() must return true.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐