美文网首页
iOS 学习笔记

iOS 学习笔记

作者: _Waiting_ | 来源:发表于2017-05-04 14:14 被阅读23次
    • (void)viewDidLoad {
      //增加监听,当键盘出现或改变时收出消息
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    //增加监听,当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    //当键盘出现或改变时调用

    • (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);
      }

    //当键退出时调用

    • (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);
    // 获取键盘弹出动画时间
    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];

     NSLog(@"键盘弹起的时间===%@",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进制转字符串

    • (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进制转10进制

    • (NSNumber *) numberHexString:(NSString *)aHexString
      {
      // 为空,直接返回.
      if (nil == aHexString)
      {
      return nil;
      }
      NSScanner * scanner = [NSScanner scannerWithString:aHexString];
      unsigned long long longlongValue;
      [scanner scanHexLongLong:&longlongValue];
      //将整数转换为NSNumber,存储到数组中,并返回.
      NSNumber * hexNumber = [NSNumber numberWithLongLong:longlongValue];
      return hexNumber;
      }

    //语音合成

    import <AVFoundation/AVFoundation.h>

    AVSpeechSynthesizer *synth2 = [[AVSpeechSynthesizer alloc] init];
    AVSpeechUtterance *utterance1 = [AVSpeechUtterance speechUtteranceWithString:@" 你瞅啥,瞅你咋滴"];//播放语
    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];//汉语
    utterance1.voice = voice;
    utterance1.rate = 0.5;//语速
    [synth2 speakUtterance:utterance1];//播放

    //一篇介绍音频的帖子

    http://www.cnblogs.com/SunnyOMGi/p/5620762.html

    //判断文件是否已经在沙盒中已经存在?

    -(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(@"这个文件已经存在:%@",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 = @"请输入内容";
        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"];
    }
    
    

    相关文章

      网友评论

          本文标题:iOS 学习笔记

          本文链接:https://www.haomeiwen.com/subject/teortxtx.html