本月主要就是UI处理相对复杂.平常业务没实现过.所以实现后做如下总结.
UItableview 折叠功能实现
- 属性
@property (assign, nonatomic) BOOL isFolding;
@property (nonatomic, strong) NSMutableArray<KeColumnCourse *> * mFoldDataArray;
@interface KeColumnCourse : MBAModel
@property (nonatomic, strong) NSString * date;
@property (nonatomic, strong) NSString * id;
@property (nonatomic, strong) NSString * picture;
@property (nonatomic, strong) NSString * time;
@property (nonatomic, strong) NSString * title;
@property (nonatomic, strong) NSString * type; //0:显示时间 1:可试听 2: 未开始 myAdd 10:锁
@property (nonatomic, strong) NSMutableArray<KeCourseDetailMaterial*> * material_list;
@property (assign, nonatomic) BOOL isOpened;
@end
- 折叠的按钮是放在tableview Section头部.头部有点击回调事件
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
KeColumnCourse *groupModel = self.mFoldDataArray[section];
KePlayTitleSectionView *view = [KePlayTitleSectionView initFromNIB];
view.tag = section;
view.bean = groupModel;
view.clickFlodStatu = ^(NSInteger tag) {
KeColumnCourse *groupModel = self.mFoldDataArray[tag];
groupModel.isOpened = !groupModel.isOpened;
if (groupModel.material_list.count > 0) {
[self reloadSection:tag withRowAnimation:UITableViewRowAnimationAutomatic];
if (groupModel.isOpened) {
self.isFolding = true;
self.mFoldPoint = self.contentOffset;
}
}
};
return view;
}
- tableview 的代理回调
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.mFoldDataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
KeColumnCourse *groupModel = self.mFoldDataArray[section];
NSInteger count = groupModel.isOpened?groupModel.material_list.count:0;
return count;
}
Uitableview嵌套了内uitableview
- 内uitableview操作
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"-----%f",scrollView.contentOffset.y);
if(self.mParentView.canScroll){
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y <= 0) { //自己全部显示状态
self.mParentView.canScroll = YES;
scrollView.contentOffset = CGPointZero;
}else{
self.mParentView.canScroll = NO;
}
}
- 主uitableview
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//x
if (fabs(scrollView.contentSize.width - self.scrollView.size.width ) >= 0.001)
{
self.canScroll = NO;
}
else
{
if (self.mCategoryArray.count > 0) { //有分类才能控制
//NSLog(@"上下移动");
//Y
if(self.numberOfSections>1){
CGFloat bottomCellOffset = [self rectForSection:1].origin.y;
if (scrollView.contentOffset.y >= bottomCellOffset) {
scrollView.contentOffset = CGPointMake(0, bottomCellOffset);
if (self.canScroll) {
self.canScroll = NO;
}
}else{
if (!self.canScroll) {//子视图没到顶部
scrollView.contentOffset = CGPointMake(0, bottomCellOffset);
}
}
}
}
}
}
- 遇到问题及解决的点:
3.1 scrollerview 水平滑动会有问题:解决要水平判断处理
3.2 当内uitableview数据量不足一屏,上拉scrollViewDidScroll会循环调用,解决:if (fabs(scrollView.contentSize.width - self.scrollView.size.width ) >= 0.001) { self.canScroll = NO; }
-(void)layoutSubviews{ [super layoutSubviews]; self.contentInset=UIEdgeInsetsZero; }
网友评论