美文网首页
小知识点总结

小知识点总结

作者: 青椒辣不辣 | 来源:发表于2018-03-01 17:11 被阅读101次

1. Xcode 修改模板:在此路径中修改相应的模板

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File\ Templates/Source/Cocoa\ Touch\ Class.xctemplate
宏的意义

2. [!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

Github在不久之前的2018年2月23号移除了一些低加密标准协议,包括TLSv1/TLSv1.1,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,相关链接在这里:Weak cryptographic standards removed
这就意味着Mac系统对应的openssl也需要更新。升级办法:stackoverflow

$ pod repo remove master
$ pod setup
$ pod install
$ pod install
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Counting objects: 2013972, done.        
  remote: Compressing objects: 100% (424/424), done.        
  remote: Total 2013972 (delta 185), reused 35 (delta 35), pack-reused 2013484        
  Receiving objects: 100% (2013972/2013972), 524.06 MiB | 921.00 KiB/s, done.
  Resolving deltas: 100% (1128315/1128315), done.
  Checking out files: 100% (224716/224716), done.

CocoaPods 1.5.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.5.0.beta.1
2018.8.28  https://gems.ruby-china.org/  域名更新为     https://gems.ruby-china.com

更新macOS High Sierra 11.3 报错:-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory

$ brew reinstall cocoapods
$ brew install ruby
$ brew link --overwrite cocoapods

ERROR: While executing gem ... (TypeError) no implicit conversion of nil into String

$ sudo gem install cocoapods
Password:
ERROR:  While executing gem ... (TypeError)
    no implicit conversion of nil into String
$ sudo gem update --system  //先更新 Ruby

3. 各种波纹动画

YSCAnimation

4. collectionView瞧不出的方法

//定义每个Cell的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size = CGSizeMake(80,80);
    return size;
}
//定义每个Section的四边间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(15, 15, 5, 15);//分别为上、左、下、右
}
//这个是两行cell之间的间距(上下行cell的间距)
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 0.8;
}
//两个cell之间的间距(同一行的cell的间距)
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
     return 0.8;
}

5. 图片

1.拉伸

UIImageView *backImgV = [RJInitViewTool rj_initImageViewWithSuperView:self.contentView];
    UIImage *image = [UIImage imageNamed:@"product_detail_pinglun_bg"];
    // 左端盖宽度
    NSInteger leftCapWidth = image.size.width * 0.5f;
    // 顶端盖高度
    NSInteger topCapHeight = image.size.height * 0.5f;
    // 重新赋值
    image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
    backImgV.image = image;

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight __TVOS_PROHIBITED;
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(5_0); // create a resizable version of this image. the interior is tiled when drawn.

2.旋转

UIImage *img = [UIImage imageNamed:@"homepage_genggai"];
    UIImage *image = [UIImage imageWithCGImage:img.CGImage scale:2.0 orientation:UIImageOrientationRight];
    imageView.image = image;

3.改变图片颜色

- (UIImage *)imageWithColor:(UIColor *)color image:(UIImage *)image{
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 1);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context, 0, image.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
    CGContextClipToMask(context, rect, image.CGImage);
    [color setFill];
    CGContextFillRect(context, rect);
    UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

4.View的内容生成一张图片

/*UIGraphicsBeginImageContextWithOptions
 CGSize size 区域大小
 BOOL opaque 是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES
 CGFloat scale 屏幕密度
 */
+(UIImage *)hbsc_imageFromView:(UIView *)view{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

6. UILabel放入图片

UILabel *imageLabel = [UILabel new];
    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    attachment.image = [UIImage imageNamed:@"product_detail_daijinquan"];
    attachment.bounds = CGRectMake(0, 0, 15, 15);
    NSAttributedString *attributedString = [NSAttributedString attributedStringWithAttachment:attachment];
    imageLabel.attributedText = attributedString;

7. iPhoneX

#define KIsiPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

//frame布局
if (@available(iOS 11.0, *)) {
    self.view.safeAreaInsets.bottom
}else {

}
//masonry布局
if (@available(iOS 11.0, *)) {
    make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
} else {
    make.bottom.equalTo(self.view);
}

8. UITableview 全局刷新跳动

self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;

8. 半透明Modal控制器解决方案

方法一

self.view.backgroundColor = [UIColor clearColor];
    self.providesPresentationContextTransitionStyle = YES;
    self.definesPresentationContext = YES;
    self.modalPresentationStyle = UIModalPresentationOverCurrentContext;

方法二(基于方法一,解决tabbar跟控制器Modal)

UIViewController *VC = [[UIViewController alloc] init];
    VC.userDetailModel = self.userDetailModel;
    [[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:VC animated:NO completion:nil];

9. UICollectionViewCell自适应大小

//该方法会出现丢cell的BUG
//layout.estimatedItemSize = CGSizeMake(20, 28);
-(UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    UICollectionViewLayoutAttributes *attributes = [super preferredLayoutAttributesFittingAttributes:layoutAttributes];
    CGRect frame = [self.textButton.titleLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 15) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObjectsAndKeys:kHCFont_26,NSFontAttributeName, nil] context:nil];
    frame.size.width = frame.size.width + 20;
    frame.size.height = 28;
    attributes.frame = frame;
    return attributes;
}
//设置每个Cell 的宽高(简单地替换方法)
//layout.itemSize = CGSizeMake(10, 28);
- (CGSize)collectionView:(UICollectionView *)collectionView  layout:(nonnull UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
     RJModel *model = self.modelArray[indexPath.row];
        CGRect frame = [model.name boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 15) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObjectsAndKeys:kHCFont_26,NSFontAttributeName, nil] context:nil];
        return CGSizeMake(frame.size.width+20, 28);
}

10. UITabBarController配置相关

//TabBarItem添加动画
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    NSInteger index = [self.tabBar.items indexOfObject:item];
    if (index != self.indexFlag) {
        //执行动画
        NSMutableArray *arry = [NSMutableArray array];
        for (UIView *btn in self.tabBar.subviews) {
            if ([btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
                [arry addObject:btn]; }}
        //添加动画
        [[arry[index] layer] addAnimation:[RJCoreTool rj_randomTransform] forKey:nil];
        //移除其他tabbar的动画
        for (int i = 0; i<arry.count; i++) {
            if (i != index) {
                [[arry[i] layer] removeAllAnimations];}}
        self.indexFlag = index;
    }
}
    //整体颜色渲染
    self.tabBar.tintColor = [UIColor blueColor];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    //未选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor randomColor],NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    //选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor randomColor],NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateSelected];

    self.tabBar.backgroundColor = [UIColor whiteColor];//不设置为半透明
    self.tabBar.backgroundImage = [UIImage imageNamed:@"Beautimage14"];

11. UINavigationController配置相关

#import "RJNavigationViewController.h"
@interface RJNavigationViewController ()<UIGestureRecognizerDelegate>

@end

@implementation RJNavigationViewController
-(void)viewDidLoad{
    [super viewDidLoad];
    // 添加全屏返回手势
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    [self.view addGestureRecognizer:pan];
    // 不允许边缘手势触发
    self.interactivePopGestureRecognizer.enabled = NO;
    // 实现滑动返回功能
    pan.delegate = self;
}
#pragma mark - UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return self.childViewControllers.count != 1;
}

+(void)load{
    // 修改当前导航控制器下导航条
    
    // 1 appearanceWhenContainedIn:获取某个类下面全局外观,获取RJNavigationViewController所有导航条
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    // 2 设置导航条标题 变大变宽 => 导航条
    bar.titleTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18]};
    // 3 设置导航条背景图片:一定要使用Default
    [bar setBackgroundImage:[UIImage imageNamed:@"beaut_1"] forBarMetrics:UIBarMetricsDefault];
    [bar setShadowImage:[UIImage new]];
}
// 设置非根控制器返回按钮
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count) {//非根控制器
        // 1 创建返回按钮
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.layer.cornerRadius = 10;
        button.layer.borderColor = WHITE.CGColor;
        button.layer.borderWidth = 1;
        [button setTitle:@"←  ⚔" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        // 2 把按钮往左边挪动
        [button sizeToFit];
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -28, 0, 0);
        // 3 覆盖系统返回按钮
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    // 4 注意。一定要记得调用super
    [super pushViewController:viewController animated:animated];
}
-(void)back{
    [self popViewControllerAnimated:YES];
}
@end

12. iOS富文本字符串AttributedString详解

13. UILabel宽度固定, 字体大小自适应

    //方法一
    self.yueL.adjustsFontSizeToFitWidth = YES;

    //方法二 : NS_DEPRECATED_IOS(2_0, 7_0)
    CGFloat fontSize;
    [self.yueL.text sizeWithFont:[UIFont systemFontOfSize:20]
                     minFontSize:10.0
                  actualFontSize:&fontSize
                        forWidth:200
                   lineBreakMode:NSLineBreakByWordWrapping];
    self.yueL.font = [UIFont systemFontOfSize:fontSize];

14. 计算文字高度

    //NS_DEPRECATED_IOS(2_0, 7_0)
    [string sizeWithFont:[UIFont systemFontOfSize:12]
          constrainedToSize:CGSizeMake(200, CGFLOAT_MAX)
              lineBreakMode:NSLineBreakByWordWrapping];

    //NS_AVAILABLE(10_11, 7_0)
    [string boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT)
                         options:NSStringDrawingUsesLineFragmentOrigin
                      attributes:@{NSFontAttributeName:font}
                         context:nil]

15. NSString 和 NSArray相互转化

   //将array数组转换为string字符串
    NSString *tempString = [array componentsJoinedByString:@","];
    //将string字符串转换为array数组
    NSArray  *tempArray  = [string componentsSeparatedByString:@","];

16. tableView顶端图片放大效果

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offsetY = scrollView.contentOffset.y;
    NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
    if (offsetY <= 0) {
        self.headerView.frame = CGRectMake(offsetY / 2.0, offsetY, kScreenWidth - offsetY, 266 - offsetY);
    }
}
- (UIView *)headerView {
    if(!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 266)];
        self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 266)];
        [self.tableView addSubview:_headerView];
    }
    return _headerView;
}

17 Mac10.13 Pod报错 / Xcode 9.4 更新报错

1、 Xcode 9.4 更新报错

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

解决:$ xcode-select --install

2、 Mac10.13 Pod报错

: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory

解决:
$ brew link --overwrite cocoapods

Error: No such keg: /usr/local/Cellar/cocoapods

$ brew reinstall cocoapods

Error: No such keg: /usr/local/Cellar/cocoapods
jiegegedexiaolingtong:HobayNew yishangyun$ brew reinstall cocoapods
==> Reinstalling cocoapods 
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.4.0.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring cocoapods-1.4.0.high_sierra.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists. You may want to remove it:
  rm '/usr/local/bin/pod'

To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods

To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods

Possible conflicting files are:
/usr/local/bin/pod
/usr/local/bin/xcodeproj
==> Summary
🍺  /usr/local/Cellar/cocoapods/1.4.0: 8,818 files, 13.0MB

//$ brew install ruby可省略该命令
$ brew link --overwrite cocoapods

Linking /usr/local/Cellar/cocoapods/1.4.0... 2 symlinks created

18 四舍五入保留两位小数

-(float)roundFloat:(float)price{
    CGFloat myF = floor(price*10000)/10000;
    return (floorf(myF*100 + 0.5))/100;
}

相关文章

  • 无标题文章

    综和复习本月知识点总结: 一:微信小程序 二:vue复习 三:js复习 四:新知识点 一:微信小程序知识点总结 开...

  • 2019-12-05 Login Button and Reco

    Salesforce小知识点总结:Enable the 'Administrators Can Login as ...

  • webApI

    总结 :小知识点 其实我看懂了下面的英文:

  • 小知识点总结

    1. Xcode 修改模板:在此路径中修改相应的模板 2. [!] Failed to connect to G...

  • 知识点小总结

    HTML部分 浏览器显示形式区分块级元素行内元素 元素特点区分替换元素非替换元素 H5新特性语义化元素 artic...

  • 小知识点总结

    最近看的东西比较杂,简要的对不太熟悉的东西做个记录,也对计算机基础知识做点回顾。 运算符 1.&*, &+, &-...

  • 小知识点总结

    小知识点总结 标签(空格分隔): 随笔 1.H5&C3新知识点 H5新标签 H5中新增了很多具有“语义化”的新标签...

  • 小知识点总结

    占坑

  • MySQL 小知识点总结

    title: MySQL 小知识点总结date: 2016-01-09update time: 2016-05-1...

  • 22年护考备考资料

    护考历年常考知识点总结 护考历年常考知识点总结

网友评论

      本文标题:小知识点总结

      本文链接:https://www.haomeiwen.com/subject/yvcnxftx.html