iOS 知识点

1、用 命令 “ -fno-objc-arc” 将ARC工程中的一个.m文件单独设置为MRC编码编译

  步骤:ProjectName -> Target -> Build Phases ->  .m -> Complier flags -> 填写命令 "-fno-objc-arc "

2、禁止 TableView的header的悬浮,添加以下代码即可

//禁止 cell header 悬浮

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    CGFloat sectionHeaderHeight = 50;

    if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {

        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {

        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

    }

}

 

3、 打印字体库

//    打印字体库

    for(NSString *familyName in [UIFont familyNames]){

        NSLog(@"Font FamilyName = %@",familyName); //*输出字体族科名字

        for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {

            NSLog(@" %@",fontName);         //*输出字体族科下字样名字

        }

    }

 

4、解决tableView cell 不贴边,在 cellForRowAtIndexPath 代理方法中添加

 

//tableViewcell 不贴边解决2

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){

        [cell setSeparatorInset:UIEdgeInsetsZero];

    }

 

5、 获取cell在tableView 中的位置 或者屏幕上的位置

  可以在didselectRowAtIndexPath方法里使用如下代码

 

  CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
  CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];

 6、获取cell在collectionView中的位置或屏幕上的位置

  -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
       UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    
    /*
     获取当前点击的cell位置大小,以此设定view2初始大小和位置
     */
    //cell在当前collection的位置
    CGRect cellRect = [_collectionView convertRect:cell.frame toView:_collectionView];
    NSLog(@"987654321- %f - %f # %f - %f",cellRect.origin.x,cellRect.origin.y,cellRect.size.width,cellRect.size.height);
    //cell在当前屏幕的位置
    CGRect rect2 = [_collectionView convertRect:cellRect toView:self.view];
    NSLog(@"987654321- %f - %f # %f - %f",rect2.origin.x,rect2.origin.y,rect2.size.width,rect2.size.height);
}

 

 

 

原文地址:https://www.cnblogs.com/wjw-blog/p/8601049.html