Am developing a ebook reader(just like ibook) for that i need to control the screen brightness of the background on image click in iphone. i did this.
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 setIma开发者_JS百科ge: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);
}
}
and am calling dis in ebook.m like this,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row]==0) {
background *back=[[background alloc] init];
[back brightness];
[self.view addSubview:back];
}
}
What's wrong with my code...when am pressing that brightness option my app getting crashed.any suggestions.
iOS 5.0 , you can use [[UIScreen mainScreen]setBrightness:1.0];
As it is obvious, there is no public API for doing this.
One way (may not be a better way) of doing this is to change the colors of your views, texts in your app between dimmer and brighter colors.
There is no Apple documented way of achieving the brightness control of screen !
Use the debugger and find out which line of code is causing the crash.
There is a private API call, but if you use it you will surely be rejected
GSEventSetBacklightLevel(0.5f);
精彩评论