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>
7. UIWebView 设置手势不触发的原因
UIWebView上设置了点击手势不触发的原因,主要是UIWebView上有一个scrollView,scrollView本身就有点击事件,为了能够响应自己定义的手势,必须要实现一个UIGestureRecognizerDelegate的代理方法
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCancle)];
self.tapGesture.delegate = self;
[self.view addGestureRecognizer:self.tapGesture];
}
- (void)clickCancle {
self.view.userInteractionEnabled = NO;
[UIView animateWithDuration:0.3 animations:^{
self.view.alpha = 0.0f;
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
}
#pragma mark - UIGestureRecognizerDelegate
//支持多手势触发. 默认为NO
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (gestureRecognizer == self.tapGesture) {
return YES;
}
return NO;
}