添加HWPanModal和FLAnimatedImage
This commit is contained in:
17
keyBoard/Class/Home/V/KBDirectionIndicatorView.h
Normal file
17
keyBoard/Class/Home/V/KBDirectionIndicatorView.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// KBDirectionIndicatorView.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/5.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <HWPanModal/HWPanModalPresentable.h>
|
||||
#import <HWPanModal/HWPanModalIndicatorProtocol.h>
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBDirectionIndicatorView : UIView<HWPanModalIndicatorProtocol>
|
||||
- (void)applyPresentationState:(PresentationState)state;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
66
keyBoard/Class/Home/V/KBDirectionIndicatorView.m
Normal file
66
keyBoard/Class/Home/V/KBDirectionIndicatorView.m
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// KBDirectionIndicatorView.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/5.
|
||||
//
|
||||
|
||||
#import "KBDirectionIndicatorView.h"
|
||||
#import "UIView+HW_Frame.h"
|
||||
|
||||
@interface KBDirectionIndicatorView ()
|
||||
@property (nonatomic, strong) UIView *leftView;
|
||||
@property (nonatomic, strong) UIView *rightView;
|
||||
@end
|
||||
|
||||
@implementation KBDirectionIndicatorView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:CGRectZero];
|
||||
if (self) {
|
||||
self.backgroundColor = UIColor.clearColor;
|
||||
_leftView = [UIView new];
|
||||
_rightView = [UIView new];
|
||||
_leftView.backgroundColor = _rightView.backgroundColor = [UIColor colorWithWhite:0.85 alpha:1];
|
||||
[self addSubview:_leftView];
|
||||
[self addSubview:_rightView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGSize)indicatorSize { return CGSizeMake(34, 13); }
|
||||
|
||||
- (void)setupSubviews {
|
||||
CGSize size = [self indicatorSize];
|
||||
self.hw_size = size;
|
||||
CGFloat h = 5, c = h/2.0;
|
||||
_leftView.frame = CGRectMake(0, 0, size.width/2 + c, h);
|
||||
_rightView.frame = CGRectMake(size.width/2 - c, 0, size.width/2 + c, h);
|
||||
_leftView.hw_centerY = _rightView.hw_centerY = self.hw_height/2.0;
|
||||
_leftView.layer.cornerRadius = MIN(_leftView.hw_width, _leftView.hw_height)/2;
|
||||
_rightView.layer.cornerRadius = MIN(_rightView.hw_width, _rightView.hw_height)/2;
|
||||
}
|
||||
|
||||
// 默认库会在很多时机传 HWIndicatorStateNormal,这里忽略,不改变我们基于状态的朝向
|
||||
- (void)didChangeToState:(HWIndicatorState)state {
|
||||
// no-op 或者根据需要做轻微弹性动画
|
||||
}
|
||||
|
||||
- (void)applyPresentationState:(PresentationState)state {
|
||||
CGFloat angle = (CGFloat)(20.0 * M_PI / 180.0);
|
||||
void (^animate)(void) = ^{
|
||||
switch (state) {
|
||||
case PresentationStateShort: // 最低:指向上(∧)
|
||||
self.leftView.transform = CGAffineTransformMakeRotation(-angle);
|
||||
self.rightView.transform = CGAffineTransformMakeRotation(angle);
|
||||
break;
|
||||
case PresentationStateLong: // 最高:指向下(∨)
|
||||
default:
|
||||
self.leftView.transform = CGAffineTransformMakeRotation(angle);
|
||||
self.rightView.transform = CGAffineTransformMakeRotation(-angle);
|
||||
break;
|
||||
}
|
||||
};
|
||||
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseOut animations:animate completion:nil];
|
||||
}
|
||||
@end
|
||||
18
keyBoard/Class/Home/VC/HomeSheetVC.h
Normal file
18
keyBoard/Class/Home/VC/HomeSheetVC.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// HomeSheetVC.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/5.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <HWPanModal/HWPanModal.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface HomeSheetVC : UIViewController<HWPanModalPresentable>
|
||||
@property (nonatomic, assign) CGFloat minHeight; // 例如 150
|
||||
@property (nonatomic, assign) CGFloat topInset; // 例如 100
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
73
keyBoard/Class/Home/VC/HomeSheetVC.m
Normal file
73
keyBoard/Class/Home/VC/HomeSheetVC.m
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// HomeSheetVC.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/5.
|
||||
//
|
||||
|
||||
#import "HomeSheetVC.h"
|
||||
#import "KBDirectionIndicatorView.h"
|
||||
|
||||
@interface HomeSheetVC ()
|
||||
@property (nonatomic, strong) KBDirectionIndicatorView *indicator;
|
||||
@end
|
||||
|
||||
@implementation HomeSheetVC
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
self.view.backgroundColor = [UIColor redColor];
|
||||
}
|
||||
|
||||
- (UIView<HWPanModalIndicatorProtocol> *)customIndicatorView {
|
||||
if (!_indicator) _indicator = [KBDirectionIndicatorView new];
|
||||
return _indicator;
|
||||
}
|
||||
|
||||
- (void)panModalTransitionDidFinish {
|
||||
// 初次展示后按当前状态设定一次朝向
|
||||
[self.indicator applyPresentationState:self.hw_presentationState];
|
||||
}
|
||||
|
||||
- (void)didChangeTransitionToState:(PresentationState)state {
|
||||
// 每次状态切换完成后刷新朝向
|
||||
[self.indicator applyPresentationState:state];
|
||||
}
|
||||
|
||||
- (PanModalHeight)shortFormHeight {
|
||||
return PanModalHeightMake(PanModalHeightTypeContent, self.minHeight ?: 300);
|
||||
}
|
||||
|
||||
- (PanModalHeight)longFormHeight {
|
||||
return PanModalHeightMake(PanModalHeightTypeMaxTopInset, self.topInset ?: 100);
|
||||
}
|
||||
|
||||
- (PresentationState)originPresentationState {
|
||||
return PresentationStateShort; // 初始就以最小高度展示
|
||||
}
|
||||
|
||||
- (BOOL)anchorModalToLongForm {
|
||||
return YES; // 到 long 后不再继续往上拖
|
||||
}
|
||||
|
||||
- (BOOL)allowsPullDownWhenShortState {
|
||||
return NO; // 在 short 状态禁止继续往下拉(锁住最小高度)
|
||||
}
|
||||
|
||||
// 可选:完全不允许拖拽关闭(避免被拉到底消失)
|
||||
- (BOOL)allowsDragToDismiss {
|
||||
return NO;
|
||||
}
|
||||
|
||||
//- (BOOL)showDragIndicator{
|
||||
// return NO;
|
||||
//}
|
||||
|
||||
// 点背景不关闭
|
||||
- (BOOL)allowsTapBackgroundToDismiss {
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -8,6 +8,7 @@
|
||||
#import "HomeVC.h"
|
||||
#import "KBGuideVC.h"
|
||||
#import "KBLangTestVC.h"
|
||||
#import "HomeSheetVC.h"
|
||||
|
||||
@interface HomeVC () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property (nonatomic, strong) UITextView *textView; // 作为表头,保持原有键盘测试
|
||||
@@ -21,37 +22,42 @@
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
CGFloat width = [UIScreen mainScreen].bounds.size.width;
|
||||
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 220)];
|
||||
CGRect frame = CGRectMake(16, 16, width - 32, 188);
|
||||
self.textView = [[UITextView alloc] initWithFrame:frame];
|
||||
self.textView.text = KBLocalized(@"home_input_placeholder");
|
||||
self.textView.layer.borderColor = [UIColor blackColor].CGColor;
|
||||
self.textView.layer.borderWidth = 0.5;
|
||||
[header addSubview:self.textView];
|
||||
|
||||
// 列表
|
||||
self.tableView = [[BaseTableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleInsetGrouped];
|
||||
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.tableView.delegate = self;
|
||||
self.tableView.dataSource = self;
|
||||
self.tableView.tableHeaderView = header;
|
||||
[self.view addSubview:self.tableView];
|
||||
|
||||
self.items = @[ KBLocalized(@"home_item_lang_test"), KBLocalized(@"home_item_keyboard_permission"), @"皮肤中心" ];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [self.textView becomeFirstResponder]; });
|
||||
|
||||
[[KBNetworkManager shared] GET:@"app/config" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
NSLog(@"====");
|
||||
}];
|
||||
// CGFloat width = [UIScreen mainScreen].bounds.size.width;
|
||||
// UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 220)];
|
||||
// CGRect frame = CGRectMake(16, 16, width - 32, 188);
|
||||
// self.textView = [[UITextView alloc] initWithFrame:frame];
|
||||
// self.textView.text = KBLocalized(@"home_input_placeholder");
|
||||
// self.textView.layer.borderColor = [UIColor blackColor].CGColor;
|
||||
// self.textView.layer.borderWidth = 0.5;
|
||||
// [header addSubview:self.textView];
|
||||
//
|
||||
// // 列表
|
||||
// self.tableView = [[BaseTableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleInsetGrouped];
|
||||
// self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
// self.tableView.delegate = self;
|
||||
// self.tableView.dataSource = self;
|
||||
// self.tableView.tableHeaderView = header;
|
||||
// [self.view addSubview:self.tableView];
|
||||
//
|
||||
// self.items = @[ KBLocalized(@"home_item_lang_test"), KBLocalized(@"home_item_keyboard_permission"), @"皮肤中心" ];
|
||||
//
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{ [self.textView becomeFirstResponder]; });
|
||||
//
|
||||
// [[KBNetworkManager shared] GET:@"app/config" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
// NSLog(@"====");
|
||||
// }];
|
||||
|
||||
HomeSheetVC *vc = [HomeSheetVC new];
|
||||
vc.minHeight = 300;
|
||||
vc.topInset = 100;
|
||||
[self presentPanModal:vc];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated{
|
||||
[super viewWillAppear:animated];
|
||||
self.title = KBLocalized(@"home_title");
|
||||
self.items = @[ KBLocalized(@"home_item_lang_test"), KBLocalized(@"home_item_keyboard_permission"), @"皮肤中心" ];
|
||||
[self.tableView reloadData];
|
||||
// self.title = KBLocalized(@"home_title");
|
||||
// self.items = @[ KBLocalized(@"home_item_lang_test"), KBLocalized(@"home_item_keyboard_permission"), @"皮肤中心" ];
|
||||
// [self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||||
|
||||
Reference in New Issue
Block a user