-1

我在应用程序中启用了接近度,当用户在传感器上长时间“点击”并且屏幕变暗时。

     //MARK:- Activate Proximity Sensor
func activateProximitySensor() {
    let device = UIDevice.current
    device.isProximityMonitoringEnabled = true

    NotificationCenter.default.addObserver(self, selector: #selector(proximityStateDidChange), name:UIDevice.proximityStateDidChangeNotification, object: device)        
}

@objc func proximityStateDidChange(notification: NSNotification) {

    if viewModel.dataSourceArrayCarousel.count > 0 {            
        currentIndexPath = IndexPath(row: self.currentPage, section: 0)
        let model  = viewModel.getModelFotCellAtIndexPathForCarousel(index: currentIndexPath.row)
        let cell = collectionView!.cellForItem(at: currentIndexPath)

        revealCard(model: model, cell: cell as! MyCardCell, indexPath: currentIndexPath)
    } }

关于如何管理这些情况的任何建议?

4

1 回答 1

2

当接近监控处于活动状态并且传感器被覆盖时,无法防止屏幕变暗。除了防止意外的耳朵接触之外,您不应该将传感器用于任何其他用途。

于 2019-05-23T17:27:19.307 回答