我想在應用程序「尤伯杯」添加背景圖與視頻(或GIF),如 我想使用視頻背景鑑於在我的應用程序很長一段時間。添加視頻背景視圖的最佳做法是什麼?
而且我想知道這些問題的答案:
- 他們什麼會消耗電池能量少
- 我可以用它在iPhone或iPad
- 性能這種方法的
屏幕截圖註冊表
我想在應用程序「尤伯杯」添加背景圖與視頻(或GIF),如 我想使用視頻背景鑑於在我的應用程序很長一段時間。添加視頻背景視圖的最佳做法是什麼?
而且我想知道這些問題的答案:
屏幕截圖註冊表
首先,
你有兩個主要選擇:使用的ImageView與GIF或使用視頻背景AVPlayer或的MPMoviePlayerController。你可以找到很多例子添加這兩種方法的,這裏有幾個:
在回答你的問題:
他們什麼都會消耗更少電池能量
Gener盟友使用視頻:正如用戶所指出的那樣,視頻通常是經過優化的,他們的編解碼器可以處理GPU;顯示GIF應該是唯一的「CPU作業」,因爲它只是顯示一幀循環。因此,能量比較是在一個簡單的幀循環(GIF)和一個更復雜的幀循環之間進行的,可以通過多種方式加速(視頻)。在我的經驗中,無論如何,一個小的GIF仍然會有很好的表現。
我可以用它在iPhone或iPad
在這兩種,但你必須要小心的寬高比和自動佈局約束性能這種方法的
在這兩種情況下都很出色,但您必須小心GIF或視頻的大小:您的文件(GIF或視頻)越大,越差表現。對於視頻更精確,質量越差的應該是性能,而視頻的持續時間不應受到影響。
爲什麼gif會消耗更少的能量? – vikingosegundo
感謝您的回答@MassimoPolimeni,我想我會在性能和質量之間找到黃金的意思。 –
@ vikingosegundo我增加了更多信息:)現在我的回答更準確。 @TikhonovAlexander;)玩得開心,做一些測試找到最佳選擇 –
您可以使用視頻直接&發揮它的重複模式,
或
你可以使用默認animationImages
UIImageView
類的屬性一起使用的圖片。
像下面,
YourImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"sample_1.png"],
[UIImage imageNamed:@"sample_2.png"],
[UIImage imageNamed:@"sample_3.png"],
[UIImage imageNamed:@"sample_4.png"],
[UIImage imageNamed:@"sample_5.png"],
nil];
// How many seconds it should take to go through all images one time.
YourImageView.animationDuration = 5.0;
// How many times to repeat the animation (0 for indefinitely).
YourImageView.animationRepeatCount = 4;
[YourImageView startAnimating];
希望這有助於你。
它看起來很容易,謝謝 –
不,謝謝。接受答案.. Upvote it ... –
可以使用組圖像.png
或.jpeg
格式實現這一目標,並指定圖像的UIImageView
:
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 548)];
//Add images which will be used for the animation using an array. Here I have created an array on the fly
NSMutableArray *drawingImgs = [NSMutableArray array];
[drawingImgs addObject:[UIImage imageNamed:@"image1.png"]];
[drawingImgs addObject:[UIImage imageNamed:@"image2.png"]];
[drawingImgs addObject:[UIImage imageNamed:@"image3.png"]];
[drawingImgs addObject:[UIImage imageNamed:@"image4.png"]];
[drawingImgs addObject:[UIImage imageNamed:@"image5.png"]];
backgroundImageView.animationImages = drawingImgs;
//Set the duration of the entire animation
backgroundImageView.animationDuration = 0.5;
//Set the repeat count. If you don't set that value, by default will be a loop (infinite)
backgroundImageView.animationRepeatCount = 1;
//Start the animationrepeatcount
[backgroundImageView startAnimating];
一個從流行和開源庫背景視頻播放庫示例源代碼下載點擊以下鏈接
願這幫助很大。
它完全滿足您的要求@TikhonovAlexander –
我用xCode 7和iOS 9. 我用gif圖像,它工作正常。
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Name of your image" ofType:@"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
webViewBG.userInteractionEnabled = NO;
[self.view addSubview:webViewBG];
「最佳實踐」問題不鼓勵提問者表現出努力。那裏 - 因爲它們不適合堆棧溢出。 http://meta.stackexchange.com/questions/142353/why-is-asking-a-question-on-best-practice-a-bad-thing – vikingosegundo
我同意你的意見,但如果我想使用那個或另一個背景方法查看很長一段時間,我想知道,它們中的哪些會消耗更少的電池能量,我可以在iPhone或iPad上使用它。 –
所以你的問題就成了一個很好的例子,爲什麼最好的實踐問題是不好的:一個人如何能夠通過要求最佳實踐來預測這個問題? – vikingosegundo