iOS 启动图添加广告动图短视频

实现原理:

在didFinishLaunchingWithOptions方法中设置完当前控制器之后,在当前window上添加一个视图显示启动图之后的效果,在这个视图上自定义添加任何想要的子控件去实现项目需求。
此处我只是封装了三种方式的,跳过(倒计时按钮)都以添加,也有提供相应的方法去自定义它的样式。

demo链接https://github.com/lypcliuli/LaunchAnimateView.git

引入方法:

  • 本地导入
    下载下来之后把LaunchAnimateView.h、LaunchAnimateView.m导入项目,在build phases里面导入依赖库AVFoundation.framework;
  • pods引入
    pod 'LaunchAnimateView'

公开的方法:

/** 外部可以通过拿到该按钮 修改成所需样式  */
@property (nonatomic,strong) UIButton *timeBtn;

/**
 设置本地图片

 @param imgName 图片名字
 @param frame 位置(以整个屏幕为父视图)
 */
- (void)configAnimateImg:(NSString *)imgName position:(CGRect)frame;

/**
 设置网络图片
 
 @param imgUrl 图片链接
 @param frame 位置(以整个屏幕为父视图)
 */
- (void)configAnimateImgUrl:(NSString *)imgUrl position:(CGRect)frame;

/**
 设置视频
 
 @param videoUrl 视频链接
 @param frame 位置(以整个屏幕为父视图)
 */
- (void)configAnimateVideoUrl:(NSString *)videoUrl position:(CGRect)frame;

/** 倒计时时长  */
@property (nonatomic,assign) int playDurition;
/** 播放完成是否重复播放  */
@property (nonatomic,assign) BOOL isRepeatPlay;

/**
 设置跳过(倒计时按钮的位置)

 @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]之后添加 这样的效果是先展示启动图,启动图结束之后展示动画图
    [self.window addSubview:self.animateView];
    [self.window bringSubviewToFront:self.animateView];
    
    // Override point for customization after application launch.
    return YES;
}

#pragma mark  通过懒加载设置
- (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;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,949评论 1 180
  • 本来不想说,想想心里不痛快,还是说出来解气 到了我们二十七八的年纪,要是还没有结婚,没有对象,难免家里人会经常催着...
    蒋铭博阅读 2,929评论 0 0
  • 做一名软件开发的程序,像比尔.盖茨一样,创建自己软件帝国。这是多少青年的梦想,有多少计算机专业的学生,希望自己也能...
    公羊仑阅读 1,495评论 0 0
  • 直须认取主人翁作两绝戏之 苏轼 有主还须更有宾, 不如无境自无尘。 自从半夜安心后, 失却当年觉痛人。
    喜亭_bf8f阅读 2,662评论 0 6