想在APP里面调节屏幕的亮度,这只是个小众需求。而且,虽然可以直接调节手机的亮度,但是它还是个需求,客户有需求,剩下的就是我们的事了,好了,吐槽到此结束。
刚拿到这个需求的人,或许想的是直接对view各种折腾,其实UIScreen里有一个Brightness属性,可以通过下面的方法直接调节:
[[UIScreen mainScreen] setBrightness : (float)brightness];
- (void)viewDidLoad {
[super viewDidLoad];
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 200, 200, 30)];
slider.minimumValue = 0;
slider.maximumValue = 1;
slider.continuous = YES;
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
CGFloat brightness = [[UIScreen mainScreen] brightness];
NSLog(@"brightness:%f",brightness);
}
- (void)sliderValueChanged:(UISlider*)sender {
NSLog(@"value:%f",sender.value);
[[UIScreen mainScreen] setBrightness:sender.value];
}