Last active
December 20, 2015 15:38
-
-
Save HituziANDO/6155240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
[self startSensor]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[super viewWillDisappear:animated]; | |
[self stopSensor]; | |
} | |
~~~ 省略 ~~~ | |
#pragma mark - Proximity Sensor | |
- (void)startSensor | |
{ | |
[UIDevice currentDevice].proximityMonitoringEnabled = YES; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil]; | |
} | |
- (void)stopSensor | |
{ | |
[UIDevice currentDevice].proximityMonitoringEnabled = NO; | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceProximityStateDidChangeNotification object:nil]; | |
} | |
/** | |
* 画面消灯は近接センサをONにするだけで実装されている | |
*/ | |
- (void)proximityStateDidChange:(NSNotification *)notification | |
{ | |
// センサに近づいたら | |
if ([UIDevice currentDevice].proximityState == YES) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment