美文网首页
iOS - 爬过的坑

iOS - 爬过的坑

作者: changsanjiang | 来源:发表于2017-07-10 18:21 被阅读524次
    1. 长时间运行的线程可能需要新建额外的autoreleasepool来频繁的释放它的对象. 取决于实际代码表现, 适当调整和使用autoreleasepool.
    2. 如果子线程触发观察回调, 则回调也会在子线程中进行。
    3. 在使用U盟分享时,如果使用的 thumImage 链接地址无效,微信相关的分享服务无法打开。
    4. 在录制短视频的时候, 将输出文件的格式改成了.mp4导致录制有时候会失败。 后来看了苹果的sample, 将格式改为了.mov.
    [self.dbMovieOutput startRecordingToOutputFileURL:self.kamera_movieOutURL recordingDelegate:self];
    
     - (NSURL *)kamera_movieOutURL {
        if ( _kamera_movieOutURL ) return _kamera_movieOutURL;
        _kamera_movieOutURL = [self.kamera_movieFolderURL URLByAppendingPathComponent:@"db_kamera_movie.mov"];
        return _kamera_movieOutURL;
    }
    
    1. 同时安装了 Xcode8.3.3 和 Xcode9 在发布 podspec 时, 报如下错误:
     -> SJVideoPlayerBackGR (1.0.0)
        - ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices
    
    xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
    ) during validation.
    
    

    解决办法:

    终端输入:   sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
    
    1. -ObjC 标志
      这个标志与 Category 有关. 引用的静态库当存在分类时需要加上这个标志.
      了解了一下这个标志的意思:
    在引用静态库时, OC没有为每个方法定义链接符号,它只为每个类创建链接符号. 
    当在一个静态库中使用类别来扩展已有类时, 链接器不会把本类方法和 Category 中的方法整合起来. 
    所以当调用 Category 中的方法时, 出现"selector not recognized", 也就是找不到方法定义的错误. 为了解决这个问题, 引入了-ObjC标志, 它的作用就是将静态库中所有的和对象相关的文件都加载进来.
    
    1. 设置 shadowOffset
      有时候设置shadowOffset不显示, 1是可能与父视图的层级关系有关. shadow被下一级的视图挡住了. 2 设置了clipsTopBounds.

    2. mac升级了系统, 用 pod 报错

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

    解决, 重装一下pod就好了:

    gem install cocoapods
    
    1. searchBar


      WechatIMG85.jpeg
        _searchBar.barTintColor = [UIColor whiteColor];
        _searchBar.searchBarStyle = UISearchBarStyleMinimal;
    

    设置bar透明:

        [_searchBar setBackgroundImage:[UIImage new]];
    
    1. 为某个视图做transform动画, 出现卡顿.
      原因是设置了阴影导致的. 加上self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath; 搞定.
      全貌:
        self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
        self.view.layer.shadowOffset = CGSizeMake(-1, 0);
        self.view.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.2].CGColor;
        self.view.layer.shadowRadius = 1;
        self.view.layer.shadowOpacity = 1;
    
    1. 父视图如何根据子视图自适应?
        [_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(0);
            make.leading.trailing.offset(0);
        }];
    
        [_subview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edge.offset(0);
            make.height.offset(50);
        }];
    
    1. transform
      /// a -> x 方向缩放
      /// b -> y 拉伸
      /// c -> x 拉伸
      /// d -> y 方向缩放
      /// tx -> x 平移
      /// ty -> y 平移
        /// 反转
        _textView.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 0);
    
    1. iOS 11 UITableView 调用reloadData后, 会抖动到别的地方. 解决办法:
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
    
    1. iOS UITableViewHeaderFooterView 设置透明
        view.backgroundColor = [UIColor clearColor];
        view.backgroundView = [UIImageView new];
        view.contentView.backgroundColor = [UIColor clearColor];
    
    1. 搜索控件可以使用定时器,当用户连续输入的时间超过一定时间时,就 开始一次搜索。这样使用延迟时间,就可以让用户在搜索前有足够的时间来输入想要 搜索的关键字。
    2. 上传版本时, 苹果发了一份邮件, 内容如下:
    Dear Developer,
    
    We identified one or more issues with a recent delivery for your app, "YourAppName". Please correct the following issues, then upload again.
    
    Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data.
    

    坑爹啊, 定位没用啊 (可能有些第三方框架里面用到了定位服务, 但是我们App确实没有定位功能). 没办法, 第三方的还得用, 只能乖乖的把 key 加到 Info.plist 中去. 再次上传后成功.

    1. NSString的UTF8String这个方法返回的C字符串(生命周期不可控), 使用之前最好strcpy一下.
    2. UIPageViewController 报错如下:
      Assertion failure in -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:]
      原因: 初始化时, 没有设置控制器(viewControllers 为空)
      解决:
        [self.pageViewController setViewControllers:@[[self _viewControllerWithIndex:0]]
                                          direction:0
                                           animated:NO
                                         completion:nil];
    
    1. 使用 NSAssert(<#condition#>, <#desc, ...#>) 第一个参数有个坑, 请放bool变量 或 判断变量是否为空, 一定不要放执行语句. 在release模式下, NSAssert 是不执行的.
    2. 删除远程tag 0.0.1
    // 先删本地
    git tag -d 0.0.1
    // 再删远程
    git push origin :0.0.1
    
    1. git403错误解决办法
      git缓存了用户, 可以按下面步骤重新设置用户名和密码
    // username 写要设置的用户名
    git remote set-url origin https://username@github.com/changsanjiang/SJVideoPlayer.git
    // 接着会提示输入密码
    
    1. 将protocols作为了一个subspec, 其中一个协议定义了一些通知如:extern NSNotificationName const LWZMP3PlaybackControllerCurrentTimeDidChangeNotification;, 在上层的文件中给出了定义, 发布podspec时, 死活验证不通过, 后来在当前文件夹中定义后, 发布成功.
      image.png
      # subspec
      s.subspec 'Protocol' do |ss|
          ss.source_files = 'LWZMP3Player/Protocol/*.{h,m}'
      end
    
    1. 添加内购测试账号时我填自己的邮箱, 总是报错发生了下列一个或多个验证错误, 后来填了一个未注册的邮箱, 邀请成功了.
      image.png
    2. 控制器中, 懒加载方法中, 最好不要调用self.view.

    相关文章

      网友评论

          本文标题:iOS - 爬过的坑

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