實現(xiàn)原理:
在didFinishLaunchingWithOptions方法中設(shè)置完當(dāng)前控制器之后蜓斧,在當(dāng)前window上添加一個視圖顯示啟動圖之后的效果,在這個視圖上自定義添加任何想要的子控件去實現(xiàn)項目需求楞捂。
此處我只是封裝了三種方式的,跳過(倒計時按鈕)都以添加,也有提供相應(yīng)的方法去自定義它的樣式承匣。
demo鏈接https://github.com/lypcliuli/LaunchAnimateView.git
引入方法:
- 本地導(dǎo)入
下載下來之后把LaunchAnimateView.h宁仔、LaunchAnimateView.m導(dǎo)入項目稠屠,在build phases里面導(dǎo)入依賴庫AVFoundation.framework; - pods引入
pod 'LaunchAnimateView'
公開的方法:
/** 外部可以通過拿到該按鈕 修改成所需樣式 */
@property (nonatomic,strong) UIButton *timeBtn;
/**
設(shè)置本地圖片
@param imgName 圖片名字
@param frame 位置(以整個屏幕為父視圖)
*/
- (void)configAnimateImg:(NSString *)imgName position:(CGRect)frame;
/**
設(shè)置網(wǎng)絡(luò)圖片
@param imgUrl 圖片鏈接
@param frame 位置(以整個屏幕為父視圖)
*/
- (void)configAnimateImgUrl:(NSString *)imgUrl position:(CGRect)frame;
/**
設(shè)置視頻
@param videoUrl 視頻鏈接
@param frame 位置(以整個屏幕為父視圖)
*/
- (void)configAnimateVideoUrl:(NSString *)videoUrl position:(CGRect)frame;
/** 倒計時時長 */
@property (nonatomic,assign) int playDurition;
/** 播放完成是否重復(fù)播放 */
@property (nonatomic,assign) BOOL isRepeatPlay;
/**
設(shè)置跳過(倒計時按鈕的位置)
@param frame 位置(以整個屏幕為父視圖)
*/
- (void)setupTimeBtnPosition:(CGRect)frame;
使用方法:
在AppDelegate.m文件中:
#import "LaunchAnimateView.h"
@interface LLAppDelegate ()
@property (nonatomic, strong) LaunchAnimateView *animateView;
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[LLViewController alloc] init];
[self.window makeKeyAndVisible];
// 注意:一定要在[self.window makeKeyAndVisible]之后添加 這樣的效果是先展示啟動圖,啟動圖結(jié)束之后展示動畫圖
[self.window addSubview:self.animateView];
[self.window bringSubviewToFront:self.animateView];
// Override point for customization after application launch.
return YES;
}
#pragma mark 通過懶加載設(shè)置
- (LaunchAnimateView *)animateView {
if (!_animateView) {
_animateView = [[LaunchAnimateView alloc] initWithFrame:self.window.bounds];
_animateView.backgroundColor = [UIColor whiteColor];
// [_animateView configAnimateImg:@"7" position:CGRectMake(0, 0, self.window.bounds.size.width, self.window.bounds.size.height)];
// [_animateView configAnimateImgUrl:@"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1521782669&di=cbdd9d2877c5f42c20886031eb16858d&src=http://p2.gexing.com/G1/M00/DE/CC/rBACE1OtbgOgJjrsAAIUK1an7OA034.jpg" position:CGRectMake(0, 0, self.window.bounds.size.width, self.window.bounds.size.height)];
_animateView.isRepeatPlay = YES;
_animateView.playDurition = 6;
[_animateView configAnimateVideoUrl:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" position:CGRectMake(0, 0, self.window.bounds.size.width, self.window.bounds.size.height)];
}
return _animateView;
}