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

方法很简单:

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


//

//  ScreenBrightness.h

//  Jump

//

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

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

//

 

#import <Foundation/Foundation.h>

 

@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

 


 

上一篇:躁动不安的年代,你需要读几本好书(python爬虫及数据分析)


下一篇:ios 添加到cell 上的button点击无效!扩大button的点击区域(黑魔法)