一个好的引导页会使得用户体验大大提升,利用视频来做,可以更简单的达到优雅的效果。
使用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
效果如图:
文章转自 neilbee的简书
时间: 2024-11-08 17:02:34