我在应用程序中启用了接近度,当用户在传感器上长时间“点击”并且屏幕变暗时。
//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)
} }
关于如何管理这些情况的任何建议?