// 进入(或前台)时获取初始亮度并赋值给属性变量,退出(或后台)时利用保存的变量进行亮度恢复,而销毁时直接更改无缓慢过程
- (void)graduallySetBrightness:(CGFloat)brightness animation:(BOOL)animation {
[self.brightnessQueue cancelAllOperations];
if (animation) {
CGFloat currentBrightness = [UIScreen mainScreen].brightness;
CGFloat stepValue = 0.005 * ((brightness > currentBrightness) ? 1 : -1);
int times = fabs((brightness - currentBrightness) / 0.005);
for (CGFloat i = 1; i < times + 1; i++) {
[self.brightnessQueue addOperationWithBlock:^{
[NSThread sleepForTimeInterval:0.005];
[UIScreen mainScreen].brightness = currentBrightness + i * stepValue;
}];
}
} else {
[UIScreen mainScreen].brightness = brightness;
}
}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].