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.
277 lines
10 KiB
277 lines
10 KiB
4 years ago
|
//
|
||
|
// TFComicBrowseSetBar.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/16.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFComicBrowseSetBar.h"
|
||
|
#import "KLSwitch.h"
|
||
|
#import "TFNightModeView.h"
|
||
|
#import <AudioToolbox/AudioToolbox.h>
|
||
|
|
||
|
#define Menu_Setting_Cell_Height 70
|
||
|
#define Menu_Setting_Bar_Height (2 * Menu_Setting_Cell_Height + PUB_NAVBAR_OFFSET)
|
||
|
|
||
|
@interface TFComicBrowseSetBar ()
|
||
|
|
||
|
@property (nonatomic ,strong) UIView *bottomView;
|
||
|
@property (nonatomic ,strong) KLSwitch *clickPageSwitch;
|
||
|
@property (nonatomic ,strong) KLSwitch *nightSwitch;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFComicBrowseSetBar
|
||
|
|
||
|
- (instancetype)init
|
||
|
{
|
||
|
if (self = [super init]) {
|
||
|
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||
|
self.backgroundColor = kBlackTransparentColor;
|
||
|
self.hidden = YES;
|
||
|
[kMainWindow addSubview:self];
|
||
|
|
||
|
NSUserDefaults *defualt = [NSUserDefaults standardUserDefaults];
|
||
|
// 默认开启
|
||
|
if (![defualt objectForKey:Enable_Click_Page]) {
|
||
|
[defualt setObject:@"1" forKey:Enable_Click_Page];
|
||
|
[defualt synchronize];
|
||
|
}
|
||
|
|
||
|
// 默认关闭
|
||
|
if (![defualt objectForKey:Enable_Click_Night]) {
|
||
|
[defualt setObject:@"0" forKey:Enable_Click_Night];
|
||
|
[defualt synchronize];
|
||
|
}
|
||
|
|
||
|
// 默认开启
|
||
|
if (![defualt objectForKey:Enable_Barrage]) {
|
||
|
[defualt setObject:@"1" forKey:Enable_Barrage];
|
||
|
[defualt synchronize];
|
||
|
}
|
||
|
|
||
|
[self createSubViews];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)createSubViews
|
||
|
{
|
||
|
self.bottomView = [[UIView alloc] init];
|
||
|
self.bottomView.backgroundColor = [UIColor whiteColor];
|
||
|
[self addSubview:self.bottomView];
|
||
|
|
||
|
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(0);
|
||
|
make.top.mas_equalTo(self.mas_bottom);
|
||
|
make.width.mas_equalTo(self.mas_width);
|
||
|
make.height.mas_equalTo(Menu_Setting_Bar_Height);
|
||
|
}];
|
||
|
|
||
|
NSInteger cellIndex = 0;
|
||
|
{
|
||
|
UIView *cell = [[UIView alloc] init];
|
||
|
cell.backgroundColor = [UIColor whiteColor];
|
||
|
[self.bottomView addSubview:cell];
|
||
|
|
||
|
[cell mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(0);
|
||
|
make.top.mas_equalTo(cellIndex * Menu_Setting_Cell_Height);
|
||
|
make.width.mas_equalTo(self.bottomView.mas_width);
|
||
|
make.height.mas_equalTo(Menu_Setting_Cell_Height);
|
||
|
}];
|
||
|
|
||
|
self.clickPageSwitch = [[KLSwitch alloc] initWithFrame:CGRectMake(1, 1, 51, 31) didChangeHandler:^(BOOL isOn) {
|
||
|
AudioServicesPlaySystemSound(1519);
|
||
|
if (isOn) {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:Enable_Click_Page];
|
||
|
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Page object:@"1"];
|
||
|
} else {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:Enable_Click_Page];
|
||
|
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Page object:@"0"];
|
||
|
}
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
}];
|
||
|
self.clickPageSwitch.onTintColor = kMainColor;
|
||
|
self.clickPageSwitch.transform = CGAffineTransformMakeScale(0.7, 0.7);//缩放
|
||
|
[cell addSubview:self.clickPageSwitch];
|
||
|
|
||
|
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Click_Page] isEqualToString:@"1"]) {
|
||
|
[self.clickPageSwitch setDefaultOnState:YES];
|
||
|
} else {
|
||
|
[self.clickPageSwitch setDefaultOnState:NO];
|
||
|
}
|
||
|
|
||
|
[self.clickPageSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerY.mas_equalTo(cell.mas_centerY);
|
||
|
make.right.mas_equalTo(cell.mas_right).with.offset(- kHalfMargin);
|
||
|
make.width.mas_equalTo(51);
|
||
|
make.height.mas_equalTo(31);
|
||
|
}];
|
||
|
|
||
|
UILabel *titleLabel = [[UILabel alloc] init];
|
||
|
titleLabel.text = TFLocalizedString(@"点击翻页");
|
||
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
titleLabel.textColor = kBlackColor;
|
||
|
titleLabel.font = kMainFont;
|
||
|
[cell addSubview:titleLabel];
|
||
|
|
||
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.bottom.mas_equalTo(cell.mas_centerY);
|
||
|
make.left.mas_equalTo(kHalfMargin);
|
||
|
make.width.mas_equalTo(SCREEN_WIDTH / 2);
|
||
|
make.height.mas_equalTo(20);
|
||
|
}];
|
||
|
|
||
|
UILabel *subTitleLabel = [[UILabel alloc] init];
|
||
|
subTitleLabel.numberOfLines = 2;
|
||
|
subTitleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - kMargin - 51.0 - kQuarterMargin;
|
||
|
subTitleLabel.text = TFLocalizedString(@"打开后可点击屏幕上下方翻页");
|
||
|
subTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
subTitleLabel.textColor = kGrayTextColor;
|
||
|
subTitleLabel.font = kFont12;
|
||
|
[cell addSubview:subTitleLabel];
|
||
|
|
||
|
[subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(titleLabel.mas_left);
|
||
|
make.top.mas_equalTo(titleLabel.mas_bottom);
|
||
|
make.right.equalTo(self.clickPageSwitch.mas_left).offset(-kQuarterMargin);
|
||
|
make.height.mas_equalTo(subTitleLabel.intrinsicContentSize.height);
|
||
|
}];
|
||
|
|
||
|
UIView *line = [[UIView alloc] init];
|
||
|
line.backgroundColor = kGrayLineColor;
|
||
|
[cell addSubview:line];
|
||
|
|
||
|
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(kMargin);
|
||
|
make.height.mas_equalTo(kCellLineHeight);
|
||
|
make.width.mas_equalTo(SCREEN_WIDTH);
|
||
|
make.bottom.mas_equalTo(cell.mas_bottom);
|
||
|
}];
|
||
|
|
||
|
cellIndex ++;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
UIView *cell = [[UIView alloc] init];
|
||
|
cell.backgroundColor = [UIColor whiteColor];
|
||
|
[self.bottomView addSubview:cell];
|
||
|
|
||
|
[cell mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(0);
|
||
|
make.top.mas_equalTo(cellIndex * Menu_Setting_Cell_Height);
|
||
|
make.width.mas_equalTo(self.bottomView.mas_width);
|
||
|
make.height.mas_equalTo(Menu_Setting_Cell_Height);
|
||
|
}];
|
||
|
|
||
|
self.nightSwitch = [[KLSwitch alloc] initWithFrame:CGRectMake(1, 1, 51, 31) didChangeHandler:^(BOOL isOn) {
|
||
|
AudioServicesPlaySystemSound(1519);
|
||
|
if (isOn) {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:Enable_Click_Night];
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Night object:@"1"];
|
||
|
} else {
|
||
|
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:Enable_Click_Night];
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Night object:@"0"];
|
||
|
}
|
||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
|
}];
|
||
|
self.nightSwitch.onTintColor = kMainColor;
|
||
|
self.nightSwitch.transform = CGAffineTransformMakeScale(0.7, 0.7); // 缩放
|
||
|
[cell addSubview:self.nightSwitch];
|
||
|
|
||
|
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Click_Night] isEqualToString:@"1"]) {
|
||
|
[self.nightSwitch setDefaultOnState:YES];
|
||
|
} else {
|
||
|
[self.nightSwitch setDefaultOnState:NO];
|
||
|
}
|
||
|
|
||
|
[self.nightSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerY.mas_equalTo(cell.mas_centerY);
|
||
|
make.right.mas_equalTo(cell.mas_right).with.offset(- kHalfMargin);
|
||
|
make.width.mas_equalTo(51);
|
||
|
make.height.mas_equalTo(31);
|
||
|
}];
|
||
|
|
||
|
UILabel *titleLabel = [[UILabel alloc] init];
|
||
|
titleLabel.text = TFLocalizedString(@"夜间模式");
|
||
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
titleLabel.textColor = kBlackColor;
|
||
|
titleLabel.font = kMainFont;
|
||
|
[cell addSubview:titleLabel];
|
||
|
|
||
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerY.mas_equalTo(cell.mas_centerY);
|
||
|
make.left.mas_equalTo(kHalfMargin);
|
||
|
make.width.mas_equalTo(SCREEN_WIDTH / 2);
|
||
|
make.height.mas_equalTo(30);
|
||
|
}];
|
||
|
|
||
|
cellIndex ++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||
|
{
|
||
|
UIView *touchView = [[touches anyObject] view];
|
||
|
if (![touchView isEqual:self.bottomView]) {
|
||
|
[self hiddenSettingBar];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)showSettingBar
|
||
|
{
|
||
|
self.hidden = NO;
|
||
|
|
||
|
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||
|
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.mas_equalTo(self.mas_bottom).with.offset(- Menu_Setting_Bar_Height);
|
||
|
}];
|
||
|
}];
|
||
|
|
||
|
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||
|
[self.bottomView.superview layoutIfNeeded];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)hiddenSettingBar
|
||
|
{
|
||
|
[self.bottomView.superview setNeedsUpdateConstraints];
|
||
|
|
||
|
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||
|
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.mas_equalTo(self.mas_bottom);
|
||
|
}];
|
||
|
}];
|
||
|
|
||
|
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||
|
[self.bottomView.superview layoutIfNeeded];
|
||
|
} completion:^(BOOL finished) {
|
||
|
self.hidden = YES;
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||
|
{
|
||
|
UIView *view = [super hitTest:point withEvent:event];
|
||
|
|
||
|
if ([self.clickPageSwitch pointInside:[self.clickPageSwitch convertPoint:point fromView:self] withEvent:event]) {
|
||
|
return self.clickPageSwitch;
|
||
|
}
|
||
|
|
||
|
if ([self.nightSwitch pointInside:[self.nightSwitch convertPoint:point fromView:self] withEvent:event]) {
|
||
|
return self.nightSwitch;
|
||
|
}
|
||
|
|
||
|
if ([self.bottomView pointInside:[self.bottomView convertPoint:point fromView:self] withEvent:event]) {
|
||
|
return self.bottomView;
|
||
|
}
|
||
|
|
||
|
return view;
|
||
|
}
|
||
|
|
||
|
@end
|