IOS中UIImageView方法實現(xiàn)簡單動畫
IOS中UIImageView方法實現(xiàn)簡單動畫
查閱UIImageView文檔時,發(fā)現(xiàn)UIImageView有一組關(guān)于動畫的方法/參數(shù),可以實現(xiàn)簡單的動畫。包括:
animationImages; highlightedAnimationImages; animationDuration; animationRepeatCount; - startAnimating; - stopAnimating; - isAnimating;
上面的這組方法很簡單,一目了然:設(shè)置好動畫的圖片、動畫時間、重復(fù)次數(shù),就可以開始動畫了。
下面用代碼舉個例子。
上面這張圖,分成16份,播放出來:
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.jpg"]]; [self.view addSubview:self.imageView]; self.imageView.frame = CGRectMake(0, 0, 150, 450); self.imageView.animationImages = @[[UIImage imageNamed:@"f-0.jpg"], [UIImage imageNamed:@"f-1.jpg"], [UIImage imageNamed:@"f-2.jpg"], [UIImage imageNamed:@"f-3.jpg"], [UIImage imageNamed:@"f-4.jpg"], [UIImage imageNamed:@"f-5.jpg"], [UIImage imageNamed:@"f-6.jpg"], [UIImage imageNamed:@"f-7.jpg"], [UIImage imageNamed:@"f-8.jpg"], [UIImage imageNamed:@"f-9.jpg"], [UIImage imageNamed:@"f-10.jpg"], [UIImage imageNamed:@"f-11.jpg"], [UIImage imageNamed:@"f-12.jpg"], [UIImage imageNamed:@"f-13.jpg"], [UIImage imageNamed:@"f-14.jpg"], [UIImage imageNamed:@"f-15.jpg"],]; self.imageView.animationDuration = 5.0; self.imageView.animationRepeatCount = 0; [self.imageView startAnimating];
動畫如下圖所示:
動畫勉強可以,用來播放簡單動畫差強人意。
然而這種方法問題不少。
占資源:數(shù)十張圖片,無論是放在Bundle里,還是加載到內(nèi)存中,對于這樣一個簡單動畫來說,似乎都占地兒太多了。
效果不咋地:主要也還是圖片數(shù)量不足;然而如果圖片數(shù)量太多,加上速度要求過快,參見問題1;
無法實現(xiàn)細膩的、動態(tài)的動畫:只能實現(xiàn)一些簡單粗暴的動畫,比如自定義的加載動畫;
而且,還有更好的替代方式,比如直接播放gif動畫,簡單方便。
對于細膩復(fù)雜的動畫,就需要調(diào)用Core Animation了。
綜上,這種方法是個雞肋。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
iOS sqlite對數(shù)據(jù)庫的各種操作(日常整理全)
在IOS中使用Sqlite來處理數(shù)據(jù)。如果你已經(jīng)了解了SQL,那你可以很容易的掌握SQLite數(shù)據(jù)庫的操作。本文給大家介紹iOS sqlite對數(shù)據(jù)庫的各種操作,需要的朋友參考下吧2016-03-03詳解ios中自定義cell,自定義UITableViewCell
本篇文章主要介紹了ios中自定義cell,自定義UITableViewCell,非常具有實用價值,需要的朋友可以參考下。2016-12-12