如何使用 Objective c 在 iOS 9.3 中为启动屏幕添加动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37112950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add animation to launch screen in iOS 9.3 using Objective c
提问by ssowri1
how to make a animated splash screen like below image in iOS 9.3.
如何在 iOS 9.3 中制作如下图所示的动画闪屏。
回答by Kubba
Basically, you can't make an animated splash screen. However, you can duplicate the launch screen in your storyboard and make it the entrance-view controller (VC) of your app. Then when the view is loaded, you can start your animation. As a final result, you will have an "animated splash screen."
基本上,您无法制作动画闪屏。但是,您可以在故事板中复制启动屏幕,并将其设为应用程序的入口视图控制器 (VC)。然后当视图加载时,你可以开始你的动画。作为最终结果,您将拥有一个“动画闪屏”。
The sequence progresses like this:
顺序是这样的:
App starts → display static launch screen → transition to entrance-VC, which won't be visible to the user because the scenes look the same → entrance-VC view is loaded as an animation.
应用程序启动 → 显示静态启动屏幕 → 转换到 entry-VC,因为场景看起来相同,所以用户看不到它 → entry-VC 视图作为动画加载。
In summary, treat your launch screen's .xib file as the first frame of your animated launch screen.
总之,将启动屏幕的 .xib 文件视为动画启动屏幕的第一帧。
回答by iOS Geek
You can check the following links for this kind of animation :
您可以查看以下链接以了解此类动画:
https://github.com/okmr-d/App-Launching-like-Twitter
https://github.com/okmr-d/App-Launching-like-Twitter
http://iosdevtips.co/post/88481653818/twitter-ios-app-bird-zoom-animation
http://iosdevtips.co/post/88481653818/twitter-ios-app-bird-zoom-animation
回答by Rahul Phate
Launch screen is static and we cannot perform any operation on launch screen. So not possible to display animation on launch screen. but we can achieve this using one way. First show static launch screen and then load viewcontroller,on that viewcontroller we can show gif of that animation. And after animation loop completes then call home screen of the app. Please refer following url for reference. for achiving animation on splash screen
启动屏幕是静态的,我们无法在启动屏幕上执行任何操作。因此无法在启动屏幕上显示动画。但我们可以使用一种方式来实现这一点。首先显示静态启动屏幕,然后加载视图控制器,在该视图控制器上我们可以显示该动画的 gif。并在动画循环完成后调用应用程序的主屏幕。请参考以下网址以供参考。 用于在启动画面上实现动画
回答by shubham mishra
In my case the animation was to rotate an image in the launchScreen,
Animated Launch Screenon YouTube
在我的情况下,动画是在启动屏幕中旋转图像,
YouTube 上的
动画启动屏幕
Step 1:
I created the launchScreen with UiImageViews as below,
第 1 步:我使用 UiImageViews 创建了 launchScreen,如下所示,
Step 2: I again created same screen in my storyBoard, and also created a viewController file for the same view, where I will write logic for the animation. I have given the name as, 'AnimatedlaunchScreenViewController'. The code for the viewController is below,
第 2 步:我再次在我的故事板中创建了相同的屏幕,并为同一个视图创建了一个 viewController 文件,我将在其中编写动画的逻辑。我已将名称命名为“AnimatedlaunchScreenViewController”。viewController 的代码如下,
class 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
}
}
}
}
In the above I First I have created Outlets, Then I have made use of Timer() for the animation period. Once the animation time period is completed I have redirected to the Home ViewController.
在上面我首先创建了 Outlets,然后我在动画期间使用了 Timer()。动画时间段完成后,我已重定向到 Home ViewController。
On the HomeScreen I have just displayed Limez label, so don't worry by seeing the same label again.
在主屏幕上,我刚刚显示了 Limez 标签,所以不要担心再次看到相同的标签。
回答by Mahendra Y
You can not add animation in splash screen but you can produce same result by creating your view controller with following two option
您不能在启动画面中添加动画,但可以通过使用以下两个选项创建视图控制器来产生相同的结果
- Add a gif image on view controller or
- Add a video in view controller
- 在视图控制器上添加 gif 图像或
- 在视图控制器中添加视频
Then when app launch, App static splash screen will show and navigate to custom view controller where animation will show either a gif or video. When video complete you will navigate to app landing screen.
然后当应用程序启动时,应用程序静态启动画面将显示并导航到自定义视图控制器,其中动画将显示 gif 或视频。视频完成后,您将导航到应用程序登陆屏幕。