- (void)viewDidLoad {
//增加監(jiān)聽孝情,當(dāng)鍵盤出現(xiàn)或改變時(shí)收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//增加監(jiān)聽,當(dāng)鍵退出時(shí)收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
//當(dāng)鍵盤出現(xiàn)或改變時(shí)調(diào)用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//獲取鍵盤的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
int height = keyboardRect.size.height;
NSLog(@"==%d",height);
}
//當(dāng)鍵退出時(shí)調(diào)用
- (void)keyboardWillHide:(NSNotification *)aNotification{}
//獲取鍵盤的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
int height = keyboardRect.size.height;
NSLog(@"===%d",height);
// 獲取鍵盤彈出動(dòng)畫時(shí)間
NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration;
[animationDurationValue getValue:&animationDuration];
NSLog(@"鍵盤彈起的時(shí)間===%@",animationDurationValue);
UIGraphics
- (void)drawViewsWithRect:(CGRect)rect
{
self.backgroundColor = [UIColor whiteColor];
UIImageView *ima = [[UIImageView alloc] initWithFrame:rect];
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
UIImage *myIma = _iconImage;
[myIma drawInRect:CGRectMake(20, 5, 34, 34)];
NSString *nameStr = _nameString;
[nameStr drawInRect:CGRectMake(60, 5, 200, 34) withAttributes:@{NSFontAttributeName: [UIFont fontWithName: @"Zapfino" size: 15]}];
UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
ima.image = im;
[self addSubview:ima];
NSLog(@"%s",FUNCTION)
}
屏幕刷新
_disPlayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateWave:)];
_disPlayLink.frameInterval = 3;//刷新頻率 1-60 2-30 3-20
[_disPlayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
/**
保持和屏幕的刷新速度相同伊佃,iphone的刷新速度是60Hz,即每秒60次的刷新
*/
-(void)updateWave:(CADisplayLink *)link
{
}
- (void)viewDidLoad {
NSString *str = @"000068976897230253444b2076657273696f00106e3a322e302e302835613837356261290020776966693a312e30";
NSString *charStr = [self convertHexStrToString:str];
NSLog(@"%@",charStr);
}
//16進(jìn)制轉(zhuǎn)字符串
- (NSString *)convertHexStrToString:(NSString *)str {
if (!str || [str length] == 0) {
return nil;
}
NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
NSRange range;
if ([str length] % 2 == 0) {
range = NSMakeRange(0, 2);
} else {
range = NSMakeRange(0, 1);
}
for (NSInteger i = range.location; i < [str length]; i += 2) {
unsigned int anInt;
NSString *hexCharStr = [str substringWithRange:range];
NSNumber *nb = [self numberHexString:hexCharStr];
NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
[scanner scanHexInt:&anInt];
NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
if ([nb integerValue] > 32 && [nb integerValue] < 127)
{
[hexData appendData:entity];
}
range.location += range.length;
range.length = 2;
}
NSString *string = [[NSString alloc]initWithData:hexData encoding:NSASCIIStringEncoding];
return string;
}
//16進(jìn)制轉(zhuǎn)10進(jìn)制
- (NSNumber *) numberHexString:(NSString *)aHexString
{
// 為空,直接返回.
if (nil == aHexString)
{
return nil;
}
NSScanner * scanner = [NSScanner scannerWithString:aHexString];
unsigned long long longlongValue;
[scanner scanHexLongLong:&longlongValue];
//將整數(shù)轉(zhuǎn)換為NSNumber,存儲(chǔ)到數(shù)組中,并返回.
NSNumber * hexNumber = [NSNumber numberWithLongLong:longlongValue];
return hexNumber;
}
//語(yǔ)音合成
import <AVFoundation/AVFoundation.h>
AVSpeechSynthesizer *synth2 = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance1 = [AVSpeechUtterance speechUtteranceWithString:@" 你瞅啥,瞅你咋滴"];//播放語(yǔ)
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];//漢語(yǔ)
utterance1.voice = voice;
utterance1.rate = 0.5;//語(yǔ)速
[synth2 speakUtterance:utterance1];//播放
//一篇介紹音頻的帖子
http://www.cnblogs.com/SunnyOMGi/p/5620762.html
//判斷文件是否已經(jīng)在沙盒中已經(jīng)存在一忱?
-(BOOL) isFileExist:(NSString *)fileName
{
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);//判斷Caches
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//判斷Document
NSString *path = [paths objectAtIndex:0];
NSString *filePath = [path stringByAppendingPathComponent:fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL result = [fileManager fileExistsAtPath:filePath];
NSLog(@"這個(gè)文件已經(jīng)存在:%@",result?@"是的":@"不存在");
return result;
}
- (void)setupTextView
{
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 100];
[textView setBackgroundColor:[UIColor greenColor]];
[self.view addSubview:textView];
// _placeholderLabel
UILabel *placeHolderLabel = [[UILabel alloc] init];
placeHolderLabel.text = @"請(qǐng)輸入內(nèi)容";
placeHolderLabel.numberOfLines = 0;
placeHolderLabel.textColor = [UIColor lightGrayColor];
[placeHolderLabel sizeToFit];
[textView addSubview:placeHolderLabel];
// same font
textView.font = [UIFont systemFontOfSize:13.f];
placeHolderLabel.font = [UIFont systemFontOfSize:13.f];
[textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
}
判斷最后一個(gè)cell
if indexPath.row == (tableView.numberOfRows(inSection: indexPath.section) - 1){}