* 动画
lottie 动画,直接将动画转成json,直接加载json就行 github.com/airbnb/lott…
self.deleteView.hidden = NO;
[UIView animateWithDuration:0.25 animations:^{
self.deleteView.transform = CGAffineTransformTranslate( self.deleteView.transform, 0, - self->_deleteViewHeight);
} completion:^(BOOL finished) {
}];
* timer DispatchSourceTimer 崩溃carsh
1.suspend/resume 必须成对出现, 否则GCD Timer内部状态紊乱非常容易Crash
- 注意在suspend状态下不能直接释放timer,否则会发生崩溃crash。可通过再调用一次resucme在释放,或 直接cancel,再释放 timer = nil
* 获取cell或者cell中的控件在屏幕中的位置
cell在屏幕中的位置
CGRectrectInTableView = [tableView rectForRowAtIndexPath:indexPath];//获取cell在tableView中的位置
CGRectrectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];
cell中的控件(比如按钮)在屏幕中的位置
UIWindow* window = [UIApplicationsharedApplication].keyWindow;
CGRectrect1 = [sender convertRect:sender.framefromView:self.contentView];//获取button在contentView的位置
CGRectrect2 = [sender convertRect:rect1 toView:window];
链接:www.jianshu.com/p/c7b40979f…
* iOS UITableView reloadData 刷新结束后执行后续操作
如果在reloadData后需要立即获取tableview的cell、高度,或者需要滚动tableview。 如果直接在reloadData后执行代码是有可能出问题的,比如indexPath为nil等等异常情况。 [tableView reloadData]并不会等待tableview更新结束后才执行后续代码, 而是立即执行后续代码,然后异步地去计算scrollView的高度,获取cell等等。 如果表中的数据非常大,在一个run loop周期没执行完, 这时就显示tableView视图数据的操作就会出问题了。
Apple并没有直接提供reloadData的api,想要程序延迟到reloadData结束在操作。
可以通过以下方法:
- 通过layoutIfNeeded方法,强制重绘并等待完成。
[self.tableView reloadData];
[self.tableView layoutIfNeeded];
//刷新完成,执行后续需要执行的代码
2.reloadData方法会在主线程执行,通过GCD,使后续操作排队在reloadData后面执行。
[self.tableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
//刷新完成,执行后续代码
});
-
UItextview 获取光标位置
let textRange:UITextRange? = self.postTextView.selectedTextRange
// 光标位置
var caretRect:CGRect?
if let textRange = textRange {
let position:UITextPosition? = self.postTextView.position(from: textRange.start, offset: 0)
if let position = position {
caretRect = self.postTextView.caretRect(for: position)
}
}
-
UIScrollView 滑动停止时 ,最后停止位置
/// 滑动停止时
/// - Parameters:
/// - velocity: 速度
/// - targetContentOffset: 停止时的contentoffset
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let targetOffSetX = targetContentOffset.pointee.x
print("---- scrollViewWillEndDragging velocity = ",velocity," targetContentOffset x = ",targetOffSetX)
}
-
tabbar默认会有阴影, 显示原图
// UIImage(named: image)?.withRenderingMode(.alwaysOriginal)
controller.tabBarItem = UITabBarItem(title: title, image: UIImage(named: image)?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: selectedImage)?.withRenderingMode(.alwaysOriginal))
-
scrollview 状态栏 向下偏移
// 解决隐藏导航栏后,scrollview, UITableView向下偏移状态栏高度
scrollview.contentInsetAdjustmentBehavior = .never
tableView.contentInsetAdjustmentBehavior = .never
-
tableview 防抖动
// 防抖动
tableView.estimatedRowHeight = kScreenHeight
tableView.rowHeight = kScreenHeight
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0
-
自定义controlelr 显示动画 用 controller.transitioningDelegate
let transitionDelegate = PPMatchSwipeTransitionDelegate(targetEdge: .right, gestureRecognizer: gesture)
controller.transitioningDelegate = transitionDelegate
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
-
tableview ,collectionview reload,reloadSections,reloadItems 取消动画
UIView.performWithoutAnimation {
self.collectionView.reloadSections([0])
}
-
uinavigationbar 透明
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
}
-
设置状态栏为白色
/// 设置状态栏为白色
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
-
替换掉当前的controller
目前测试iOS8.1及以上可直接使用先pop后push
-
安装权限
Mac OS X 10.11系统以后,/usr/local/等系统目录下的文件读写是需要系统root权限的,以往的Homebrew安装如果没有指定安装路径,会默认安装在这些需要系统root用户读写权限的目录下,导致有些指令需要添加sudo前缀来执行,如果你不想每次都使用sudo指令,你有两种方法可以选择:
1、安装Homebrew时对安装路径进行指定,直接安装在不需要系统root用户授权就可以自由读写的目录下
<安装路径> -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、对/usr/local 目录下的文件读写进行root用户授权
$ sudo chown -R $USER /usr/local
例如:
$ sudo chown -R zachary /usr/local
参考 developer.aliyun.com/article/654…
-
textview 下划线
textView.linkTextAttributes = [NSAttributedString.Key.underlineStyle:NSUnderlineStyle.single.rawValue]
一定要带rawValue要不然不起作用 参考 www.hangge.com/blog/cache/…