ios - How to set screen brightness with fade animations? -
is possible animate screen brightness change on ios 5.1+? using [uiscreen mainscreen] setbrightness:(float)]
think abrupt change ugly.
i don't know if "animatable" in other way, yourself. instance following example code hooked "full bright" , "half bright" buttons in ui. uses performselector...afterdelay change brightness 1% every 10ms till target brightness reached. pick appropriate change rate based on experimenting. refresh rate is, think, 60 hz there no point in doing change @ interval smaller 1/60th of second (my example rate chosen have nice math). although might want on non-ui thread, doesn't block ui.
- (ibaction)fullbright:(id)sender { cgfloat brightness = [uiscreen mainscreen].brightness; if (brightness < 1) { [uiscreen mainscreen].brightness += 0.01; [self performselector:@selector(fullbright:) withobject:nil afterdelay:.01]; } } - (ibaction)halfbright:(id)sender { cgfloat brightness = [uiscreen mainscreen].brightness; if (brightness > 0.5) { [uiscreen mainscreen].brightness -= 0.01; [self performselector:@selector(halfbright:) withobject:nil afterdelay:.01]; } }
Comments
Post a Comment