How to adjust the brightness of the device from our app in iPad

北城余情 提交于 2019-12-10 10:31:24

问题


I am developing a eBook reader app for iPad and i want to add a feature where in the user can adjust the brightness of the device from the app. Is there anyway in which i can implement this in my app..???


回答1:


I found rather a simple solution for it. I am adding a UIVIew of clear color to my book reader view and i am increasing the alpha component of this view upon the slider value changed event. By doing this , my view gets darkened and we get a feeling that the brightness of the app is reduced.. This solution may not be very appropriate, but works just fine in my case. Any better solutions are always appreciated.Thank you...




回答2:


well, its not the exact solution, but it will serve the purpose...

 -(IBAction)sliderValueChangedForBrightness:(UISlider*)sliderObj{

    brightnessView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:1-sliderObj.value];
}

-(IBAction)adjustBrightness:(UIButton *)sender{   

    if(isbrightnessViewShowing==NO){
        isbrightnessViewShowing=YES;
        [self.view addSubview:brightnessSliderView];
        brightnessSliderView.frame=CGRectMake(sender.frame.origin.x-70,brandingView.frame.size.height, brightnessSliderView.frame.size.width, brightnessSliderView.frame.size.height);
    }
    else {
        isbrightnessViewShowing=NO;
        [brightnessSliderView removeFromSuperview];
    }

    if (brightnessView==nil) {
        brightnessView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrollView.frame.size.width, scrollView.frame.size.height)];
        brightnessView.backgroundColor = [UIColor clearColor];
    }

    [webView addSubview:brightnessView];
    [webView bringSubviewToFront:brightnessView];       
}


来源:https://stackoverflow.com/questions/6149884/how-to-adjust-the-brightness-of-the-device-from-our-app-in-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!