我有在我的應用程序啓動畫面上顯示進度指示器的要求。 這必須從iOS 8+開始。 如何在啓動畫面上顯示進度指示器gif圖像。任何想法。試圖通過幾種方式實現,如下所述。在啓動畫面上顯示gif圖像ios8
1.使用xcode6中引入的啓動畫面選項。但stil沒有相關的.m文件來定製它以顯示進度指示器。
我有在我的應用程序啓動畫面上顯示進度指示器的要求。 這必須從iOS 8+開始。 如何在啓動畫面上顯示進度指示器gif圖像。任何想法。試圖通過幾種方式實現,如下所述。在啓動畫面上顯示gif圖像ios8
1.使用xcode6中引入的啓動畫面選項。但stil沒有相關的.m文件來定製它以顯示進度指示器。
您可以使用LaunchScreen.xib並添加一個指示器,但只會非常簡短地顯示。
我會做一個新的視圖控制器,例如SplashViewController,包含你的進度動畫(甚至動畫GIF,但我認爲你將不得不使用uiwebview),並在啓動時啓動。 通過這種方式,您可以控制要顯示多長時間。
當你完成顯示它,殺死它並正常啓動你的應用程序。
你可以提供示例代碼片段:已經嘗試過但不成功 – Avilam
一個基本的例子...你只需要在didFinishLaunchingWithOptions中調用這個方法,做你想做的事情(在我的情況下,我從服務器加載設置)你完成了,切換到你的主或應用程序或任何你想去的地方。 UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@「StartFlow」bundle:nil]; SplashViewController * controller =(SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@「SplashViewController」]; UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:controller]; self.window.rootViewController = nvc; – abavisg
您可以使用圖像序列,以顯示你的動畫,這裏是代碼:
NSMutableArray *images = [[NSMutableArray alloc] init];
//don't forget to add your images to images array
animationImageView.animationImages = images;
animationImageView.animationDuration = 1.0;
//animationImageView.clipsToBounds = NO;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
GIF圖像不玩的UIImageView本身就需要使用一類或某事:
這一個應該做的,我認爲:https://github.com/mayoff/uiimage-from-animated-gif/
或者如果你想把它當作一個進步HUD您可以使用此一:GiFHUD-Swift
編輯: Giorgos也是對的,您應該使用新的視圖控制器,或者您可以直接將UIImage
添加到窗口來控制啓動畫面的持續時間。
- (void)showSplashWithDuration:(CGFloat)duration
{
// add splash screen subview ...
UIImage *image = [UIImage imageNamed:@"splash.png"];
UIImageView *splash = [[UIImageView alloc] initWithImage:image];
splash.frame = self.window.bounds;
splash.autoresizingMask = UIViewAutoresizingNone;
[self.window addSubview:splash];
// block thread, so splash will be displayed for duration ...
CGFloat fade_duration = (duration >= 0.5f) ? 0.5f : 0.0f;
[NSThread sleepForTimeInterval:duration - fade_duration];
// animate fade out and remove splash from superview ...
[UIView animateWithDuration:fade_duration animations:^ {
splash.alpha = 0.0f;
} completion:^ (BOOL finished) {
[splash removeFromSuperview];
}];
}
&你可以說它是在didFinishLaunchingWithOptions這樣的:
[self showSplashWithDuration:3.0];
我一直在使用其提供的Xcode 6.but新推出的屏幕試過我一直在使用我的應用程序的一個這種方法做了不成功。我可以顯示靜態圖像,但不顯示gif圖像或進度指示器。要求它必須像啓動屏幕上的snapdeal應用程序顯示一樣工作。一個加載指示器。 – Avilam