[iOS AutoLayout动画 坑] AutoLayout动画平移坑总结 => Swift/OC
来源:互联网 发布:985软件工程硕士 编辑:程序博客网 时间:2024/06/06 03:55
参考帖子:自动布局 Autolayout 报错:Unable to simultaneously satisfy constraints.
参考帖子: Auto Layout 进阶
参考帖子:谈StoryBoard上AutoLayout的约束动画
学习尝试使用Swift做约束动画 实现这样的效果
===>> 往下刷 <<===
⬇️⬇️⬇️
结果 我在学习的时候出现的效果是
↘️↙️
↗️↖️
这样的缩进方式 我瞬间蛋疼了
解决方法是
1.在确保设置好约束
2.一定要在 -(void)viewDidAppear:(BOOL)animated
方法中实现动画 不然要么不执行 要么执行奇怪的动画 (都可以 关键是第三条)
-(void)viewDidAppear:(BOOL)animated
方法中实现动画 不然要么不执行 要么执行奇怪的动画3. 在动画代码写好,强制更新约束的时候
[self.chongjiboView layoutIfNeeded];
确保强制更新约束的对象 这个是❌ 的
[self.view layoutIfNeeded];
是正确的 ✅ (这个要看你动画对象, 这里也作为一个坑写出来,反正我是被教学视频的坑了一下)
4. 如果出现
“`Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don’t want. Try this: (1) look at each constraint and try to figure out which you don’t expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you’re seeing NSAutoresizingMaskLayoutConstraints that you don’t understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
“
这种类似的 估计是你约束设置的不对 (肯能冲突/可能约束超出 好像不影响反正)
5.如果要在一开始修改约束 一定要在 - (void)viewDidLoad
方法里写,如果写在viewDidApper方法 好像不起作用
%%%%%%以上就是坑总结,下面是swift / oc 的代码 %%%%%%%
swift
override func viewDidLoad() { super.viewDidLoad() self.scanlineCons.constant = -300}override func viewDidAppear(_ animated: Bool) { self.scanlineCons.constant = 300 UIView.animate(withDuration: 1.0) { UIView.setAnimationRepeatCount(MAXFLOAT) self.view.layoutIfNeeded() }}
oc
(void)viewDidLoad {
[super viewDidLoad];self.topCons.constant = -300;
// [self.chongjiboView setTranslatesAutoresizingMaskIntoConstraints:NO];
}(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[UIView animateWithDuration:2.0 animations:^{
self.topCons.constant = 300;
[UIView setAnimationRepeatCount:88];
[self.view layoutIfNeeded];
}];
}
- [iOS AutoLayout动画 坑] AutoLayout动画平移坑总结 => Swift/OC
- AutoLayout---动画
- iOS Masonry autoLayout 动画详解
- iOS Autolayout约束动画化
- IOS autoLayout 简单的使用动画效果
- iOS AutoLayout Constraint如何实现动画效果
- iOS中动画和AutoLayout的冲突
- iOS 通过constraint 进行autolayout的动画
- ios Autolayout改变约束, 动画效果处理
- [IOS 开发] Autolayout约束动画化
- AutoLayout下Constraint动画
- 基于Autolayout的动画
- AutoLayout正确动画方式
- AutoLayout 浅析动画
- AutoLayout(III):浅析动画
- iOS动画——啥?AutoLayout还能做动画?
- Autolayout约束动画化-Animating Autolayout Constraints
- 自动布局:AutoLayout注意事项及autolayout动画
- oracle 定时任务
- SQL第十七章项目案例:QQ用户信息管理系统
- hduoj 1421搬寝室【动态规划】
- linux系统常用工具命令方法整理
- 微信公众平台 获取用户openid
- [iOS AutoLayout动画 坑] AutoLayout动画平移坑总结 => Swift/OC
- QQ管理器
- def 定义函数的用法
- Qt 树形控件QTreeWidget
- JavaScript基础
- iOS的数据序列化(又称持久化)的两类使用方式
- 关于代码审查,在目前公司中深有提会
- 在代码中动态控制button的宽高
- 直接上传图片到数据库,当页面超过上传大小时分布提交