加载中…
个人资料
国学APP大全
国学APP大全
  • 博客等级:
  • 博客积分:0
  • 博客访问:228,081
  • 关注人气:48
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

UICollectionView 滚动到指定section位置

(2017-06-17 11:48:14)
标签:

ios开发

uicollectionview

跳转

分类: iPhone/iPad儿童App
- (void) segmentedAction:(id)sender {
    if ([sender isKindOfClass:[UISegmentedControl class]])
    {
        UISegmentedControl * segment = sender;
        
        [_sectionArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
         {
             if (segment.selectedSegmentIndex == idx)//
             {
                 if (self.collectionloaded)
                 {
                     segmented.selectedSegmentIndex = idx;
                     // scroll to selected index
                     NSIndexPath* cellIndexPath = [NSIndexPath indexPathForItem:0 inSection:idx];
                     UICollectionViewLayoutAttributes* attr = [myCollenctionV.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:cellIndexPath];
                     UIEdgeInsets insets = myCollenctionV.scrollIndicatorInsets;
                     
                     CGRect rect = attr.frame;
                     rect.size = myCollenctionV.frame.size;
                     rect.size.height -= insets.top + insets.bottom;
                     CGFloat offset = (rect.origin.y + rect.size.height) - myCollenctionV.contentSize.height;
                     if ( offset > 0.0 ) rect = CGRectOffset(rect, 0, -offset);
                     
                     [myCollenctionV scrollRectToVisible:rect animated:YES];
                 }
             }

             
         }];
        
    }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有