开发过程中的小知识点总结(五)

1.对数组中的元素去重的方法之一

  //对可变数组进行去重

NSMutableArray *phoneArray = [NSMutableArray array];

   for (int i = 0; i < person.persons.count; i++) {

       [phoneArray addObject:person.persons[i].phones.firstObject.phone];

}
    NSOrderedSet *set = [NSOrderedSet orderedSetWithArray:phoneArray];  //利用NSOrderedSet里元素的互异性
if (set.array.count == 1) {
    nsLog(@"phoneArray数组去重成功");
}

//对不可变数组进行去重

NSMutableArray *phoneArray = [NSMutableArray array];

   for (int i = 0; i < person.persons.count; i++) {

      [phoneArray addObject:person.persons[i].phones.firstObject.phone];

 }
NSArray *array = [NSArray arrayWithArray:phoneArray];   
NSSet *set = [NSSet orderedSetWithArray:array];  //利用NSSet里元素的互异性
NSArray *setArray = set.allObjects;

if (setArray.count == 1) {
    nsLog(@"phoneArray数组去重成功");
}

//试了一下,NSSet只能对NSArray去重,不能对NSMutableArray去重;  NSOrderedSet可以对NSMutableArray去重;

 

2.NSArray和NSMutableArray转换的方式之一

// NSArray --> NSMutableArray

NSMutableArray *mutableArray = [myArray mutableCopy];

// NSMutableArray --> NSArray

NSArray *myArray = [mutableArray copy];

3.利用NSCharacterSet的stringByTrimmingCharactersInSet方法判断字符串是否为纯数字。

//stringByTrimmingCharactersInSet函数可以过滤字符串中的指定特殊符号,如下我们指定输入的字符串过滤掉十进制数字,只要判断剩下的字符串是否为空就行,为空则都是数字,反之不然。

- (BOOL)isNum:(NSString *)checkedNumString {
    checkedNumString = [checkedNumString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
    if(checkedNumString.length > 0) {
        return NO;
    }
    return YES;
}

//附一个NSCharacterSet使用大全
https://blog.csdn.net/siji1449590363/article/details/46325459

4.简单的毛玻璃效果实现方法之一

    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.alpha = 0.8;
    //必须给effcetView的frame赋值,因为UIVisualEffectView是一个加到UIIamgeView上的子视图.
    effectView.frame = CGRectMake(50, 100, 100, 100);
    [self.view addSubview:effectView];
    
    self.textView = [[UIView alloc] init];
    self.textView.frame = CGRectMake(50, 100, 100, 100);
    self.textView.backgroundColor = HexAlphaColor(0xffffff, 0.8);
    [self.view addSubview:self.textView];

    //保持这个代码顺序,在同一个区域,effectView先加载,self.textView后加载就会实现毛玻璃模糊效果;
    //effectWithStyle三种风格
    //UIBlurEffectStyleExtraLight,
    //UIBlurEffectStyleLight,
    //UIBlurEffectStyleDark,

 

5.传入字符串生成二维码

#pragma mark - 根据字符串生成二维码
- (CIImage *)creatQRcodeWithUrlstring:(NSString *)urlString{

    // 1.实例化二维码滤镜
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    // 2.恢复滤镜的默认属性 (因为滤镜有可能保存上一次的属性)
    [filter setDefaults];
    // 3.将字符串转换成NSdata
    NSData *data  = [urlString dataUsingEncoding:NSUTF8StringEncoding];
    // 4.通过KVO设置滤镜, 传入data, 将来滤镜就知道要通过传入的数据生成二维码
    [filter setValue:data forKey:@"inputMessage"];
    // 5.生成二维码
    CIImage *outputImage = [filter outputImage];
    return outputImage;
}
//生成的是CIImage对象,在显示的时候还需要先转换为UIImage对象

CIImage *ciImage = [self  creatQRcodeWithUrlstring:@"https://itunes.apple.com/app/id1015272838"];
UIImage *qrcodeImage = [UIImage imageWithCIImage:ciImage];
self.qrcodeImageView.image = qrcodeImage;

参考链接:https://blog.csdn.net/zhuming3834/article/details/50832953

         https://www.jianshu.com/p/1895826f3cb3

 

6. WKWebView 播放视频时要求小屏播放

客户端实现:
 //配置信息
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    //设置为YES即可
    config.allowsInlineMediaPlayback = YES;
    //在初始化时讲配置信息传入
    WKWebView *mWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - TopFullHeight) configuration:config];

服务端实现:
<video preload='auto' id='my-video'  

    src='https://www.seastart.tv/introduce.mp4'  

    webkit-playsinline='true'                            /*这个属性是ios 10中设置可以,让视频在小窗内播放,也就是不是全屏播放*/

    playsinline='true'                                        /*ios微信浏览器支持小窗播放*/

    'x-webkit-airplay='allow'    

    x5-video-player-type='h5'                          /*启用同城播放器*/

    x5-video-player-fullscreen='true'               /*全屏设置,设置为true是防止全屏*/

    x5-video-ignore-metadata='true'

    width='100%' height='100%' controls><p> 不支持video</p> </video>

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章