我正在开发一个电子书阅读器(就像ibook一样),因为我需要在iPhone上点击图像来控制背景的屏幕亮度。我这样做了。
background.m
-(void)brightness
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:@"brightness.jpg"];
button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[button setImage:image forState:UIControlStateNormal];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image1 = [UIImage imageNamed:@"brightness.jpg"];
button1.frame = CGRectMake(0, 0, image1.size.width, image1.size.height);
[button1 setImage:image forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(brightnessControl:) forControlEvents:UIControlEventTouchUpInside];
gBrightnessSetting=100;
brightnessOverlay = [[CALayer alloc] init];
brightnessOverlay.masksToBounds = YES;
brightnessOverlay.backgroundColor = [[[UIColor blackColor] colorWithAlphaComponent:1.0] CGColor];
brightnessOverlay.opacity = 0.0;
[self.layer addSublayer:brightnessOverlay];
bottomButtonsSize = SCREENWIDTH/5;
}
- (void)dealloc {
[brightnessLessButton release];
[brightnessMoreButton release];
[super dealloc];
}
- (void) setLayerFrames {
brightnessOverlay.frame = CGRectMake(self.layer.bounds.origin.x,self.layer.bounds.origin.y,self.bounds.size.width,self.layer.bounds.size.height);
}
-(void)brightnessControl:(id)sender
{
if(brightnessOverlay.opacity <= 0.05) {
}else{
double newBrightness = (brightnessOverlay.opacity-0.15);
brightnessOverlay.opacity = newBrightness;
NSLog(@"BRIGHTNESS FLOAT %f",brightnessOverlay.opacity);
gBrightnessSetting=100-(int)(newBrightness*100);
NSLog(@"BRIGHTNESS Value %d%%",gBrightnessSetting);
}
}
我正在电子书中调用dis,像这样,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row]==0) {
background *back=[[background alloc] init];
[back brightness];
[self.view addSubview:back];
}
}
我的代码有什么问题...当我按下亮度选项时我的应用程序崩溃了。有什么建议。
答案 0 :(得分:3)
iOS 5.0,你可以使用[[UIScreen mainScreen] setBrightness:1.0];
答案 1 :(得分:2)
很明显,没有公共API可以做到这一点。
这样做的一种方式(可能不是更好的方法)是更改应用中视图,文本的颜色在调光器和更亮的颜色之间。
答案 2 :(得分:1)
没有Apple记录的实现屏幕亮度控制的方法!
答案 3 :(得分:1)
使用调试器并找出导致崩溃的代码行。
答案 4 :(得分:0)
有私人API调用,但如果您使用它,肯定会被拒绝
GSEventSetBacklightLevel(0.5f);