如何使动画闪屏像下面的图像在 iOS 9.3。
基本上,你不能制作一个动画闪屏。但是,你可以在你的故事板中复制启动屏幕,并使它成为你的应用程序的入口视图控制器 (VC)。然后当视图加载时,你可以开始你的动画。作为最终结果,你会有一个“动画闪屏”。
序列的进展是这样的:
应用程序启动 → 显示静态启动屏幕 → 过渡到入口-VC,这对用户来说是不可见的,因为场景看起来相同 → 入口-VC 视图作为动画加载。
总之,将启动屏幕的.xib 文件视为动画启动屏幕的第一帧。

启动屏幕是静态的,我们不能在启动屏幕上执行任何操作。所以不可能在启动屏幕上显示动画。但是我们可以用一种方法来实现。首先显示静态启动屏幕,然后加载 viewcontroller,在 viewcontroller 上我们可以显示该动画的 gif。动画循环完成后,然后调用应用程序的主屏幕。请参考以下网址以供参考。for achiving animation on splash screen
In my case the animation was to rotate an image in the launchScreen,
Animated Launch Screen on YouTube
Step 1:
I created the launchScreen with UiImageViews as below,
步骤 2:我再次在我的 storyBoard 中创建了相同的屏幕,并且还为相同的视图创建了一个 viewController 文件,在那里我将为动画编写逻辑。我已经给出了名称为 'AnimatedlaunchScreenViewController'。viewController 的代码如下,
cl AnimatedlaunchScreenViewController: UIViewController {
@IBOutlet weak var limezTitleImageView: UIImageView!
@IBOutlet weak var limezRoratingImageViewOutlet: UIImageView!
var timer: Timer?
var timeCount: Int = 0
let animationSeconds: Int = 3
override func viewDidLoad() {
super.viewDidLoad()
setTimerAndAnimateLaunchScreen()
}
//MARK: Animating flash Screen
func setTimerAndAnimateLaunchScreen(){
//Set Timer
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(checkForTimerAndRedirect), userInfo: nil, repeats: true)
let rotation = CABasicAnimation(keyPath: "transform.rotation")
rotation.fromValue = 0
rotation.toValue = 2 * Double.pi
rotation.duration = 1.1
rotation.repeatCount = Float.infinity
self.limezRoratingImageViewOutlet.layer.add(rotation, forKey: "Spin")
}
@objc func checkForTimerAndRedirect(){
if timeCount == animationSeconds{
//Redirect to LogIn or HomePage
timer?.invalidate()
timer = nil
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let homeVC = storyboard.instantiateViewController(withIdentifier: "HomePageViewController") as! HomePageViewController
//Below's navigationController is useful if u want NavigationController
let navigationController = UINavigationController(rootViewController: homeVC)
appDelegate.window!.rootViewController = homeVC
}else{
//Increment the counter
timeCount += 1
}
}
}
在上面我首先创建了 Outlet,然后我使用了 Timer()的动画周期。一旦动画时间段完成,我已经重定向到 Home ViewController。
在 HomeScreen 上,我刚刚显示了 Limez 标签,所以不要担心再次看到相同的标签。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(66条)