到目前为止,我拥有的是覆盖整个屏幕的 UITextView
。 UIImageView
设置为同一屏幕的顶部。
viewDidAppear
上的 UITextView 的内容偏移了 UIImageView
高度,因此它们不会重叠。
当 UITextView
滚动时,我尝试更新其内容偏移量,以便文本向上移动。巧合的是,我希望 UIImageVIew
至少向上移动。
注释 block 是我的第一次尝试,它将 UIImageView
向上移动,但一些约束或某些东西阻止它 100% 工作
func scrollViewDidScroll(scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
print("scrollViewDidScroll Y offset:" + offsetY.description)
print("Constraints: ")
for constraint in detailImage!.constraints {
print(constraint.description)
}
//imageFrame.origin.x = originImgFrameX
//imageFrame.origin.y = originImgFrameY - offsetY
//print("Origin is: \(imageFrame.origin.x, imageFrame.origin.y)")
//detailImage!.frame = imageFrame;
//print("IMG AFTER SCROLL: " + detailImage!.description)
}
最佳答案
我建议使用约束来执行时刻,而不是操纵框架...特别是如果您在界面生成器中设置带有约束的 View 。
您可以将约束作为导出按住 Ctrl 键拖动到代码中,然后您可以不更改 View frame.y
而是更改 constraintOutlet.constant
关于ios - UITextView 的视差效果使顶部的 UIImageView 在 Swift 中缩小并消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434722/