美文网首页
iOS 启动图添加广告动图短视频

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

作者: LYPC_下里巴人 | 来源:发表于2018-03-26 09:25 被阅读255次

实现原理:

在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;
}

相关文章

网友评论

      本文标题:iOS 启动图添加广告动图短视频

      本文链接:https://www.haomeiwen.com/subject/tvylcftx.html