iphone - 屏幕亮度控制

标签 iphone objective-c ios

我正在开发一个电子书阅读器(就像 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/

相关文章:

ios - 如何像踢足球一样轻弹 SKSpriteNode

iphone - CALayer 似乎没有定义

ios - Swift 中非可选变量可以为 nil 吗?

iphone - EKEvent 在 iOS5 中损坏?

iphone - 将 NSString 转换为 NSInteger

ios - 如何在 UITextField 中写入文本并在 uiWebview 中写入 textField 时发送文本?

iphone - Xcode 4.2 首选项 "Support Wirelessly Connected Devices"有什么作用?

android - 代码中的电子邮件和 Android 邮件帐户设置

iphone - 动画开始但似乎没有继续

iphone - 有在线 .plist 编辑器吗?