ios - UITextView 的视差效果使顶部的 UIImageView 在 Swift 中缩小并消失

标签 ios iphone swift uitextview parallax

到目前为止,我拥有的是覆盖整个屏幕的 UITextViewUIImageView 设置为同一屏幕的顶部。

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/

相关文章:

ios - mmap() 失败 : Cannot allocate memory size: 268435456 offset: 2684354560 on RealmSwift 2. 10.2

ios - 在 iOS 应用程序包中包含数据

iphone - 关于内存泄漏的问题(包括 Instruments 的屏幕截图)

iphone - 如何知道用户何时切换响铃/静音(静音)按钮?

xcode - 如何将披露按钮设置为 UItableViewCell

ios - 当我们将应用程序重新提交到 App Store 时,我们是否应该更改可用日期?

ios - 自定义 UICollectionViewCell 中的 UIImageView 始终返回 nil

ios - 禁用和重新启用 Touch ID 时出现钥匙串(keychain)错误 -25300 (errSecItemNotFound)

swift - 什么决定了返回 JSON 的顺序?

ios - 尝试通过构造函数创建对象时,在展开 Optional 值时意外发现 nil