Files
yuyin_ios/SweetParty/主类/音悦新增/交友厅/DLPKTimeInsertView.m
2025-08-08 11:05:33 +08:00

104 lines
3.0 KiB
Objective-C
Executable File

//
// DLPKTimeInsertView.m
// SweetParty
//
// Created by bj_szd on 2022/6/6.
//
#import "DLPKTimeInsertView.h"
@interface DLPKTimeInsertView () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@end
@implementation DLPKTimeInsertView
- (void)awakeFromNib {
[super awakeFromNib];
[self.confirmBtn styleGradiBlueColor];
// self.insertTF.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"请设置增加分钟" attributes:@{NSForegroundColorAttributeName:HEXCOLORA(0xFFFFFF, 0.8)}];
self.insertTF.delegate = self;
[self.insertTF becomeFirstResponder];
WEAK_SELF
[self.touchImgV dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasDown:)
name:UIKeyboardWillHideNotification object:nil];
}
///键盘高度变化的通知
- (void)keyboardWasShown:(NSNotification *)aNotification {
NSDictionary *info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:1 animations:^{
self.mainViewBottomCon.constant = kbSize.height;
}];
}
///键盘高度变化的通知
- (void)keyboardWasDown:(NSNotification *)aNotification {
[UIView animateWithDuration:1 animations:^{
self.mainViewBottomCon.constant = 0;
}];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (self.insertTF.text.length <= 0) {
[HelpPageDefine showMessage:@"请设置增加分钟"];
return NO;
}
if (self.onSendBlock) {
self.onSendBlock(self.insertTF.text);
}
[self removeFromSuperview];
return YES;
}
- (IBAction)onSend:(id)sender {
if (self.insertTF.text.length <= 0) {
[HelpPageDefine showMessage:@"请设置增加分钟"];
return;
}
if (self.onSendBlock) {
self.onSendBlock(self.insertTF.text);
}
[self removeFromSuperview];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return [self validateNumber:string];
}
- (BOOL)validateNumber:(NSString*)number {
BOOL res = YES;
NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
int i = 0;
while (i < number.length) {
NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
NSRange range = [string rangeOfCharacterFromSet:tmpSet];
if (range.length == 0) {
res = NO;
break;
}
i++;
}
return res;
}
@end