加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 04:41:38 所属栏目:百科 来源:网络整理
导读:我想在UIViewController上面显示一个UIAlertController,里面有一个UICollectionView.集合视图需要专注于启动,所以我覆盖了preferredFocusableView变量,如下所示: override var preferredFocusedView: UIView? { return self.collectionView} 使用tvOS 9一切
我想在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读