1.UITableView問題
1.UITableView滾動到頂部
有好幾種方法 常用:
tableView.setContentOffset(CGPoint.zero, animated: true)
如果有上啦加載更多就會導(dǎo)致滾動位置不準(zhǔn)確的問題
解決方法:
tableView.estimatedRowHeight = 0
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0
2.tableView內(nèi)邊距適配
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}else {
automaticallyAdjustsScrollViewInsets = false
}
2.關(guān)于UITextField設(shè)置了模式為isSecureTextEntry = true 再次編輯時就會清空的問題
解決方法:代理里面監(jiān)聽判斷
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的問題
項(xiàng)目中Xib和Storyboard里面顏色的值一直都是sRGB的模式設(shè)置的但是設(shè)計師確實(shí)用的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;
}
}