iDev

iOS Dev Tip code로 화면 밝기 조절

KraZYeom 2012. 6. 10. 13:11
반응형

밤이나 너무 밝은 곳에서는 앱이 너무 밝거나 어두운 경우가 생긴다. 

터치값 보고 위아래 움직이는 정도에 따라 밝기 조절. 


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];

    CGPoint location = [touch locationInView:[touch view]];

    previousPoint = location.y;

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];

    CGPoint location = [touch locationInView:[touch view]];

    

    float _brightness = (previousPoint/100 - location.y/100);   

    

    if (_brightness < 0) _brightness = 0;

    else if (_brightness > 1) _brightness = 1;

    

    [[UIScreen mainScreen] setBrightness:_brightness]; // 사실 이것만 중요 ㅋ


}


반응형