- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我会为您简短而详细地说明。到目前为止我取得的成功:
1) 我为所需的约束(中心 X 对齐)创建了一个导出。我不知道这是否重要,但我根据需要更改了乘数 (3:1)
2)动画他的常量
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.btn_option_layout.constant = self.nan_view.center.x //Get center x value
self.nan_view.layoutIfNeeded() // Parent View
})
问题:
对象的来源位置:
而不是像这样将 View 动画化到中心 X:
它出于某种原因使他向左移动,这是结果:
我希望我说得足够清楚了,伙计们。感谢您的宝贵时间。
计算约束常数以使其在 X 上居中的正确方法是什么?
最佳答案
您正在尝试做的是完全正确的。您有一个约束将一个 View 的中心固定到另一个 View 的中心。如果该约束的乘数为 1,则该 View 将位于另一个 View 的中心。
但是您的乘数不是 1。而且,正如您正确观察到的那样,您不能更改现有约束的乘数 — 它是只读的。
但是,没问题。简单地用不同的约束替换整个约束,与第一个约束相同,只是它的乘数是 1。现在动 Canvas 局!一个鲜为人知的事实是,您可以为这种约束变化设置动画。
这是实际代码:
let con2 = NSLayoutConstraint(item: self.con.firstItem, attribute: self.con.firstAttribute, relatedBy: self.con.relation, toItem: self.con.secondItem, attribute: self.con.secondAttribute, multiplier: 1, constant: 0)
NSLayoutConstraint.deactivateConstraints([self.con])
NSLayoutConstraint.activateConstraints([con2])
UIView.animateWithDuration(1, animations: {self.view.layoutIfNeeded()})
这里是一个循环的 gif,显示了生成的动画到中心:
关于ios - 将自动布局约束常量 X 动画化到父 View 的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30333538/
我有一个包含 10 行的 UITableView。每个单元格中都有一个 UITextField。 问题是,当我单击底部单元格中的 UITextField 时,键盘会弹出并阻止该单元格。我该如何处理这个
我真的很喜欢动态图表的外观 here但我想为其他一些图(而不仅仅是散点图)制作动画。 例如,是否可以制作烛台图的动画? 最佳答案 尽管您提出了问题,但我的回答就好像您不关心使用 googleVis,只
我一直在尝试为 UserControl 的打开设置动画,但没有成功,想知道是否有人可以提供帮助? 我有一个 UserControl,它只保存有关记录的信息。它在现有页面上作为一个框打开,但是我希望该框
This question (及其答案)让我达到了我想要的一半。 但现在我陷入了下一部分,(老实说)我什至不确定这是否可能。 我已经这样定义了一个单元格... class ExpandableCell
这个问题在这里已经有了答案: jQuery animate and property values in percentage (6 个答案) 关闭 9 年前。
多年来我一直在尝试为这个下拉菜单制作动画,花了几个小时编辑我认为相关的所有内容,但它仍然不起作用。我有几个链接页面、HTML5 中的源代码、几个引导页面以及一个样式表。这是源代码:
我目前遇到有关动画的 iOS 开发问题。我目前正在使用以下代码制作一个“幻灯片动画”,用于在手势识别器触发后切换标签栏项目。 -(void)slideToTab:(int)controllerInde
如何为 ListView 中新添加的项目设置动画? 我有一个适配器,当我在列表中添加新项目时,我说adapter.notifyDataSetChanged(); 添加了项目,一切正常,但我的问题是我想
我想为我的 UICollectionView 中的变化设置动画。我将 collectionView 作为 @IBOutlet: @IBOutlet weak var collectionView: U
我想为我的 UIView 中的子层设置 backgroundColor 更改动画(在 tintColorDidChange 上)。 我需要多次将图层的当前背景颜色设置为新的色调(每次不同的色调),因此
我正在尝试在选择 View 时使用幻灯片为 NSTabView 的每个 View 设置动画。我以一种时尚的方式工作,但它只会在我第一次选择新的选项卡 View 时进行动画处理。之后我在切换选项卡 Vi
假设我们有一个按钮 I'm a button .It's position is right in the center.Now when i click this button it should
我有一个可以正确设置动画的简单线条 SVG。问题是在第一次加载 SVG 路径时显示然后在开始之前消失。我尝试将 st1 和 st2 上的不透明度设置为 0,然后将关键帧设置为不透明度 1。这种方法有效
在我的应用程序中,我在一个动态改变宽度的场景中有一个 UITableView。当宽度改变时,我为场景的扩展设置动画 - 包括 UITableView。 UITableView 包含带有自定义 View
UIKit 文本输入组件,例如 UITextView 和 UITextField 有一个属性 inputView 来添加自定义键盘。我有两个与此相关的问题。 如果键盘当前可见并且该属性设置为新的输入
我正在尝试制作粒子轨迹的视频。但是,不知何故我的场景永远不会更新。这是一个非常简单的例子: from __future__ import absolute_import, division, prin
在我的 iPhone 应用程序中,我需要实现一种不同类型的过渡。 那是 从当前 View 打开下一个 View , 它像一个点,点像圆圈一样慢慢扩大,圆圈内下一个 View 将部分显示,圆圈内部分显示
有没有办法在 Windows Phone 8.1 Runtime 中平滑地设置 ScrollViewer 的垂直偏移动画? 我已经尝试使用 ScrollViewer.ChangeView() 方法,无
我有一个具体问题和一个一般问题。 我必须使用 javascript(没有框架)为拖动设置动画,我认为最好使用 translate() 而不是更改顶部和左侧,至少为了更好的性能。 但它是用户驱动界面的一
我在 Web 应用程序中动态设置 iFrame 的内容。是的,不幸的是需要使用 iFrame:) 没有使用跨域内容 我能够设置内容,在 iframe 中查找元素等。但现在我想为 iframe 中的一些
我是一名优秀的程序员,十分优秀!