【发布时间】:2016-06-12 10:44:41
【问题描述】:
我在使用滑块移动 UIImageView 时遇到了一些问题。这是我目前正在使用的代码:
@IBOutlet weak var titanic: UIImageView!
...
let screenWidth = UIScreen.mainScreen().bounds.width
let titanicWidth = titanic.bounds.size.width
let viewcenter = titanicWidth / 2
let slidervalue = CGFloat(sender.value)
let value = (screenWidth * slidervalue * (1.0 - titanicWidth / screenWidth)) + viewcenter
titanic.center.x = CGFloat(value)
print(value)
实际上,我可以使用此代码移动图像,但是:不知何故,图像总是“跳”回到屏幕中间的原始位置,根本不移动滑块......你有什么想法吗?这怎么可能发生?我已经检查了右边的检查器是否有一些可能导致这种效果的奇怪属性,但没有运气......
【问题讨论】:
-
你是否对 imageView 使用了约束?
-
不,我什至删除了整个图像并重新添加它......完全没有效果
-
好的,什么时候跳回来?就在释放滑块之后或者如果您更改滑块位置?
-
释放滑块后不久
-
嗯...而且您的打印还打印出该值等于 viewCenter?
标签: ios swift uiimageview uislider