这只是我遇到的一个关于为我当前的应用程序设置设置移动背景图像动画的快速问题。本质上,我想让当前静止的背景图像在我的视图中从左到右无休止地滚动;但我正在努力将它们拼凑在一起。我从各种其他来源编写了这个当前不起作用的函数,而且我真的不知道如何或为什么。
func animate(_ image: UIImageView) {
UIView.animate(withDuration: 5, delay: 0, options: .curveLinear, animations: {
image.transform = CGAffineTransform(translationX: -100, y: 0)
}) { (success: Bool) in
image.transform = CGAffineTransform.identity
self.animate(image)
}
}
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助/协助!
只是很快就想询问我在尝试在我的快速应用程序的启动屏幕中播放声音效果时遇到的一个小问题。我对于在哪里声明我的 AVAudio 播放器(在我的视图控制器或 Appdelegate 中)感到更加困惑;但两种方法都没有取得成功。这是我目前在 appDelegate 文件中得到的内容
import UIKit
import AVFoundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var audioPlayer = AVAudioPlayer()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window!.backgroundColor = UIColor(red: 9/255, green: 4/255, blue: 68/255, alpha: 1)
self.window!.makeKeyAndVisible()
// rootViewController from StoryBoard
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let navigationController = mainStoryboard.instantiateViewController(withIdentifier: "navigationController")
self.window!.rootViewController = navigationController
// logo …Run Code Online (Sandbox Code Playgroud)