我正在开发一个电子书阅读器(就像 ibook),因为我需要控制在 iphone 中单击图像时背景的屏幕亮度。我做到了。
背景.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);
}
}
我在 ebook.m 中这样调用 dis,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row]==0) {
background *back=[[background alloc] init];
[back brightness];
[self.view addSubview:back];
}
}
我的代码有什么问题...当我按下那个亮度选项时我的应用程序崩溃了。任何建议。
最佳答案
iOS 5.0,可以使用[[UIScreen mainScreen]setBrightness:1.0];
关于iphone - 屏幕亮度控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4790169/