我在应用程序中启用了接近功能,并且当用户在传感器上长按“轻击”并且屏幕变暗时。
//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)
} }
关于如何处理此类情况的任何建议?
答案 0 :(得分:1)
当接近监控处于活动状态并且传感器被遮盖时,无法防止屏幕变暗。除了防止意外的耳朵接触,您不应将传感器用于其他任何用途。