swift5 如何实现这样的布局,求高手指点一下

2022-06-30 11:50:39 +08:00
 DreamCMS
上面的是一张长图,不是视频,向左自动滚动。

5911 次点击
所在节点    iDev
14 条回复
MX123
2022-06-30 11:54:06 +08:00
scrollView
InternetExplorer
2022-06-30 12:04:25 +08:00
直接用个动画就好了吧
Building
2022-06-30 12:16:38 +08:00
superview.frame: screen.bounds
imageview.frame: screen.bounds.insets(x: -50, y: 0).offset(x: 50, y: 0)
uiview.animate(duration: 60) { imageview.frame = imageview.frame.offset(x: 50, y: 0) }
Freeego
2022-06-30 12:20:21 +08:00
scrollView 里放个 UIImageView ,动画块里更新 contentOffset
chchengeng
2022-06-30 14:25:14 +08:00
好奇 滚动完了 会停止吗。还是 会循环滚动啊?
DreamCMS
2022-06-30 14:59:29 +08:00
@chchengeng 滚完了就进里面了,类似开机画面、启动页这种
365473321
2022-06-30 15:33:22 +08:00
用 CADisplayLink 处理 frame 就行了
neptuno
2022-06-30 15:47:41 +08:00
可以用 rive ,前段时间接触了一下,,各种动画都能做,还是很强大的
justin2018
2022-06-30 17:11:34 +08:00
@neptuno

https://rive.app/

这动画工具好强大 免费版也能用很多功能
zjw7sky
2022-06-30 19:56:00 +08:00
lottie 这个了解下
icebarley
2022-06-30 23:17:37 +08:00
如果 swiftUI 开发的话原生代码就能实现
V2SuperUser
2022-07-01 09:56:15 +08:00
```swift
import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let screenBounds = UIScreen.main.bounds

let imageView = UIImageView(image: UIImage(named: "24110307_5"))
view.addSubview(imageView)
let imageW = screenBounds.width + 100
imageView.frame = CGRect(x: 0, y: 0, width: imageW, height: screenBounds.height)


//方式 1
// UIView.animate(withDuration: 4) {
// imageView.frame = CGRect(x: -100, y: 0, width: imageW, height: screenBounds.height)
// } completion: { isFinished in
// if isFinished{
// print("结束")
// }
// }

//方式 2:
let animation = CABasicAnimation()
animation.keyPath = "transform.translation.x"
animation.fromValue = 0
animation.toValue = -100
animation.duration = 4
animation.isRemovedOnCompletion = false
animation.fillMode = .forwards
imageView.layer.removeAllAnimations()
imageView.layer.add(animation, forKey: nil)

}

}
```
neptuno
2022-07-01 10:06:10 +08:00
@justin2018 是的,自己的 app 可以采用这种,真的能省很多时间
LINAICAI
2022-07-01 10:59:59 +08:00
讲道理这里应该用动画或者放个视频吧,方便后台更换,原生实现可以但不太好。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/863160

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX