开发遇到的问题(持续更新)

1.UITableView问题

1.UITableView滚动到顶部
有好几种方法 常用:
tableView.setContentOffset(CGPoint.zero, animated: true)

如果有上啦加载更多就会导致滚动位置不准确的问题

解决方法:
tableView.estimatedRowHeight = 0
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0

2.tableView内边距适配
if #available(iOS 11.0, *) {
            tableView.contentInsetAdjustmentBehavior = .never
        }else {
            automaticallyAdjustsScrollViewInsets = false
        }

2.关于UITextField设置了模式为isSecureTextEntry = true 再次编辑时就会清空的问题

解决方法:代理里面监听判断

 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

        let toBeString = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
        if textField.isSecureTextEntry  {
            textField.text = toBeString;
            return false
        }
        return true
    }

2,颜色空间Color Space的问题

项目中Xib和Storyboard里面颜色的值一直都是sRGB的模式设置的但是设计师确实用的displayP3的模式,所以就要全部改过来,在github上找到了工具XCode-Color-Fixer 但是里面的颜色模式是写死的需要自己更改,然后依照上面的方法就ok
源代码

#!/usr/bin/php -q
<?php
echo "=== XCode Color Space Fixer ===", "\n";
echo "Any Question? PonyCui@me.com", "\n";
echo "root = ", getcwd(), "\n";

$root = getcwd();

$files = scandir($root);
$isXcodeProj = false;
foreach ($files as $file) {
    if (strpos($file,'.xcodeproj') !== false) {
        $isXcodeProj = true;
    }
}

if ($isXcodeProj) {
    echo "isXcodeProj = true", "\n";
}
else {
    die("[Error] Not a valid xcode project directory!"."\n");
}

scanInterfaceBuilderFiles($root);

function scanInterfaceBuilderFiles($dir) {
    $files = scandir($dir);
    foreach ($files as $file) {
        if ($file == '.' || $file == '..' || $file == 'Pods') {
            continue;
        }
        else if (is_dir($dir.'/'.$file)) {
            scanInterfaceBuilderFiles($dir.'/'.$file);
        }
        else {
            if (strpos($file, '.storyboard') !== false || strpos($file, '.xib') !== false) {
                $changed = replaceColorSpace($dir.'/'.$file);
                echo 'file = ', $file, " " ,($changed ? "[Change]" : "[OK]"), "\n";
            }
        }
    }
}

function replaceColorSpace($filePath) {
    $fileContents = file_get_contents($filePath);
    $replaceContents = str_replace('colorSpace="custom" customColorSpace="sRGB"', 'colorSpace="custom" customColorSpace="displayP3"', $fileContents);
    if($replaceContents == $fileContents) {
        return false;
    }
    else {
        file_put_contents($filePath, $replaceContents);
        return true;
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,801评论 1 32
  • 一.UITextField属性 0.enablesReturnKeyAutomatically 默认为No,如果设...
    奋斗ing0310阅读 5,600评论 0 2
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 9,149评论 2 7
  • 筱暀/文 此时此刻,你拖着疲惫的身体,还在回家的公交上;你已经好多天没有睡个安稳觉了;你此刻倍感压力;你甚至觉得...
    筱旺阅读 1,560评论 0 0
  • 爱好之与人生,无论怎样强调其重要性都不过分。爱好给我们日常生活涂上五彩斑斓的色彩,每一样爱好带领我们探索不同的神秘...
    Lucycee阅读 650评论 0 2