之前一直用的Swift,回长沙做的第一个项目是OC。算是重新捡起OC的知识吧。
1、目前项目用到的一些第三方:
pod 'SDWebImage'
pod 'AFNetworking'
pod 'SVProgressHUD'
pod 'Toast'
pod 'YYKit'
pod 'MJRefresh'
pod 'MJExtension'
pod 'AAChartKit'
pod 'Masonry'
pod 'JXCategoryView'
pod 'BRPickerView'
pod 'AliyunOSSiOS'
pod 'SGQRCode', '~> 3.5.1'
#pod 'IQKeyboardManager'
pod 'DZNEmptyDataSet'
pod 'ZLCollectionViewFlowLayout'
pod 'JXBWebKit'
pod 'PinYin4Objc', '~> 1.1.1'
pod 'TPKeyboardAvoiding'
键盘处理一开始用的IQKeyboardManager,但是涉及到一个页面UITableViewCell都是输入框,导致点击输入框不自动马上响应(会先收起上一个响应的键盘,点第二次才会弹出键盘的问题),后面改用了TPKeyboardAvoiding。
2、UICollectionView不同的section的itemSize滑动会出现复用问题:
设置identifier解决。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *identifier=[NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
[_collectionView registerClass:[CFClientStatusFilterCollectViewCell class] forCellWithReuseIdentifier:identifier];
CFClientStatusFilterCollectViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.itemModel = [[self.dataArr objectAtIndex:indexPath.section].items objectAtIndex:indexPath.row];
return cell;
}
3、身份证校验:
才知道直接校验15/18位数身份证验证是不精准的。
新的二代公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位校验码。
https://www.jianshu.com/p/9405ced634ee
4、iOS 15适配:
if (@available(iOS 15.0, *)) {
[UITableView appearance].sectionHeaderTopPadding = 0;
}
// 设置导航主题
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
// [appearance configureWithOpaqueBackground];
[[UINavigationBar appearance]setTintColor:UIColor.whiteColor];
appearance.titleTextAttributes = textAt;
[appearance setBackgroundImage:[UIImage imageWithColor:kCFMainColor]];
[[UINavigationBar appearance] setScrollEdgeAppearance:appearance];
[[UINavigationBar appearance] setStandardAppearance:appearance];
} else {
self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.shadowImage = [[UIImage alloc] init];
[self.navigationBar setBackgroundImage:[UIImage imageWithColor:kCFMainColor] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:textAt];
}
目前是做了这两块的适配,其他没什么问题。
5、IQKeyboardManager不支持YYTextView和其他自定义TextView控件响应:
IQKeyboardManager不支持YYTextView的响应是因为没有监听YYTextView的自定义通知。
手动监听通知即可。
[[IQKeyboardManager sharedManager] registerTextFieldViewClass:[YYTextView class] didBeginEditingNotificationName:YYTextViewTextDidBeginEditingNotification didEndEditingNotificationName:YYTextViewTextDidEndEditingNotification];
不过项目最后也没用IQKeyboardManager管理键盘了。
6、UITableView行高问题:
大部分其实可以使用Masonry约束控件和UITableView的UITableViewAutomaticDimension实现,用了真的很方便呀。
其他的就直接根据Model内容自己算吧。
7、iPad横屏竖屏适配处理:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doRotateAction:) name:UIDeviceOrientationDidChangeNotification object:nil];
- (void)doRotateAction:(NSNotification *)notification {
[self addChangeThePage];
}
-(void)addChangeThePage {
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait
|| [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
self.collectionView.frame = self.collectionView.frame;
self.isLandNo = NO;
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft
|| [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
self.collectionView.frame = self.view.bounds;
self.isLandNo = YES;
}
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
if (self.isLandNo) {
self.collectionView.frame = self.view.bounds;
}else{
self.collectionView.frame = self.collectionView.frame;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});
}
8、数据请求传值字典优化:
一开始我都是直接以下:
NSDictionary *params = @{
@"name": self.todayToDoModel.name
}
改成下面可以防止控制闪退问题:
NSMutableDictionary *params =[[NSMutableDictionary alloc]init];
[params setValue:@"" forKey:@"name"];
9、UIPageViewController的使用:
实现Tab切换的content,可以使用UIPageViewController。
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:(UIPageViewControllerTransitionStyleScroll) navigationOrientation:(UIPageViewControllerNavigationOrientationHorizontal) options:nil];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
再然后实现切换代理即可。
10、图表第三方库:AAChartKit
11、tableView滚到指定位置:
一开始使用scrollToRow,但是不好用,顶部总差点,
[self.tableView scrollToRow:0 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
老老实实用setContentOffset吧,疑惑的是为啥scrollToRow为啥会差点。
[self.tableView setContentOffset:CGPointZero animated:NO];
网友评论