支付宝付款页面调整屏幕亮度

方法很简单:

            [UIScreen mainScreen].brightness = 0-1(屏幕亮度范围);
但是对眼睛伤害不利;采用逐渐变亮的方法:


//

//  ScreenBrightness.h

//  Jump

//

//  Created by peter.zhang on 2017/4/24.

//  Copyright © 2017年 redstar. All rights reserved.

//

 

#import

 

@interface ScreenBrightness : NSObject

- (void)graduallyResumeBrightness:(CGFloat)brightness;

@end

 




//

//  ScreenBrightness.m

//  Jump

//

//  Created by peter.zhang on 2017/4/24.

//  Copyright © 2017年 redstar. All rights reserved.

//

 

#import "ScreenBrightness.h"

 

@interface ScreenBrightness()

 

@property (nonatomic, strong)NSOperationQueue *queue;

 

@property (nonatomic, assign)CGFloat currentBrightness;

 

@end

 

@implementation ScreenBrightness

 

- (instancetype)init{

    self = [super init];

    if (self) {

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveDefaultBrightness) name:UIScreenBrightnessDidChangeNotification object:nil];

        [self saveDefaultBrightness];

 

    }

    return self;

}

 

- (void)graduallySetBrightness:(CGFloat)value{

    if (!_queue) {

        _queue = [[NSOperationQueue alloc] init];

        _queue.maxConcurrentOperationCount = 1;

    }

    [_queue cancelAllOperations];

    

    CGFloat brightness = [UIScreen mainScreen].brightness;

    CGFloat step = 0.005 * ((value > brightness) ? 1 : -1);

    int times = fabs((value - brightness) / 0.005);

    for (CGFloat i = 1; i < times + 1; i++) {

        [_queue addOperationWithBlock:^{

            [NSThread sleepForTimeInterval:1 / 180.0];

            [UIScreen mainScreen].brightness = brightness + i * step;

        }];

    }

}

 

- (void)saveDefaultBrightness{

    _currentBrightness = [UIScreen mainScreen].brightness;

}

 

 

- (void)graduallyResumeBrightness:(CGFloat)brightness{

    [self graduallySetBrightness:brightness];

}

 

@end

 


 

转载于:https://www.cnblogs.com/PeterWolf/p/6757524.html

你可能感兴趣的:(支付宝付款页面调整屏幕亮度)