You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
65 lines
1.8 KiB
4 years ago
|
//
|
||
|
// TFReadNovelBackgroundController.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/15.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFReadNovelBackgroundController.h"
|
||
|
#import "TFReaderSettingHelper.h"
|
||
|
#import "TFAdvertisementManager.h"
|
||
|
|
||
|
@interface TFReadNovelBackgroundController ()
|
||
|
|
||
|
@property (nonatomic ,weak) UIImageView *backgroundImageView;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFReadNovelBackgroundController
|
||
|
|
||
|
- (instancetype)init
|
||
|
{
|
||
|
if (self = [super init]) {
|
||
|
[self createSubviews];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
|
||
|
|
||
|
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
|
||
|
backgroundImageView.backgroundColor = self.view.backgroundColor;
|
||
|
self.backgroundImageView = backgroundImageView;
|
||
|
[self.view addSubview:backgroundImageView];
|
||
|
}
|
||
|
|
||
|
- (void)updateWithViewController:(UIViewController *)viewController
|
||
|
{
|
||
|
self.backgroundImageView.frame = viewController.view.bounds;
|
||
|
self.backgroundImageView.image = [self captureView:viewController.view];
|
||
|
self.backgroundImageView.alpha = 0.6;
|
||
|
}
|
||
|
|
||
|
- (UIImage *)captureView:(UIView *)view
|
||
|
{
|
||
|
UIImage * __block image = nil;
|
||
|
kCodeSync({
|
||
|
CGRect rect = view.bounds;
|
||
|
UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f);
|
||
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
||
|
|
||
|
CGAffineTransform transform = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0, rect.size.width, 0.0);
|
||
|
CGContextConcatCTM(context,transform);
|
||
|
[view.layer renderInContext:context];
|
||
|
image = UIGraphicsGetImageFromCurrentImageContext();
|
||
|
UIGraphicsEndImageContext();
|
||
|
});
|
||
|
|
||
|
return image;
|
||
|
}
|
||
|
|
||
|
@end
|