iOS获取开屏LaunchScreen对象

在给App加入开屏广告时,发现LaunchScreen和开屏广告衔接处需要通过一张截图来过渡. 但是不同尺寸的屏幕上得放不同截图. 于是我想了个办法,能不用直接用LaunchScreen 作为截图.

以下是解决办法.

//拿到LaunchScreen.StoryBoard并生成一个控制器
UIViewController *stvc = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateInitialViewController];

//通过控制器的.view生成imgae截图
CGRect rect = view.bounds;
UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//之后拿到了image就可以用作开屏广告前的截图了
比如腾讯广告中就会用到
[TXAD configOpenScreenAD:image fullImg:image placementId:TAD_OpenScreenPlaceId];


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容