NSP*_*tik 13 catransform3d uiviewanimationtransition ios uiview-hierarchy swift
这是一张图片,解释了我想做的一切:

我的问题是,我将如何制作我的视图结构.表视图的标题应固定在表的顶部.但是在表格视图标题上方的最顶层图像呢?我是否必须在UIScrollView中添加表视图?
视差效果可以通过CATransform3D,但我如何实现我想要的,这是我的问题.有很多演示,但我想让它完成自定义.
您可以将图像视图添加到视图中,例如 -
let imageView = UIImageView()
let lblName = UILabel()
imageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 300)
imageView.image = UIImage.init(named: "poster")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
view.addSubview(imageView)
lblName.frame = CGRect(x: 20, y: 100, width: 200, height: 22)
lblName.text = "Steve Jobs"
lblName.textColor = UIColor.white
lblName.font = UIFont.systemFont(ofSize: 26)
lblName.clipsToBounds = true
imageView.addSubview(lblName)
Run Code Online (Sandbox Code Playgroud)
之后,在 tableview 委托方法中,您可以添加如下scrollviewDidScroll方法 -
let y = 300 - (scrollView.contentOffset.y + 300)
let height = min(max(y, 60), 400)
imageView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: height)
lblName.frame = CGRect(x: 20, y: height - 30, width: 200, height: 22)
Run Code Online (Sandbox Code Playgroud)
我希望这会有所帮助。如果我错了,请纠正我。
| 归档时间: |
|
| 查看次数: |
14347 次 |
| 最近记录: |