一個好的引導頁會使得用戶體驗大大提升,利用視頻來做,可以更簡單的達到優雅的效果。
使用MediaPlayer.framework框架下的AVPlayerLayer,它和Core Animation緊密地結合在一起,提供了一個CALayer子類來顯示自定義的內容類型。
加入MediaPlayer.framework及
#import #import
核心代碼:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{int Offset = _scroll.contentOffset.x/_scroll.frame.size.width;if (Offset == lastindex) { return; }if (Offset == 0) { [avPlayer1 seekToTime:kCMTimeZero]; [avPlayer1 play]; [avPlayer2 seekToTime:kCMTimeZero]; [avPlayer2 pause]; [avPlayer3 seekToTime:kCMTimeZero]; [avPlayer3 pause]; _pagecontrol.currentPage = 0; }else if (Offset == 1) { [avPlayer2 seekToTime:kCMTimeZero]; [avPlayer2 play]; [avPlayer1 seekToTime:kCMTimeZero]; [avPlayer1 pause]; [avPlayer3 seekToTime:kCMTimeZero]; [avPlayer3 pause]; _pagecontrol.currentPage = 1; }else if (Offset == 2) { [avPlayer3 seekToTime:kCMTimeZero]; [avPlayer3 play]; [avPlayer1 seekToTime:kCMTimeZero]; [avPlayer1 pause]; [avPlayer2 seekToTime:kCMTimeZero]; [avPlayer2 pause]; _pagecontrol.currentPage = 2; } lastindex = Offset;}
主要通過UIScrollView的代理來實現現在是哪一頁面。
下載地址:https://github.com/sinceresk/SIHomePage
效果如圖: