简单 Objective C 类别用于视频背景。CROCOVideoBackground 类是由 UIView 扩展而来的 Objective C 类别,它提供了一种简单的方法将视频背景放入 UIView。此类旨在使显示视频、播放和停止视频快速且简单。视频应为 .mp4 格式。
将 CROCOVideoBackground.h 和 CROCOVideoBackground.m 拷贝到您的项目中。就这么简单。
非常简单,就像使用 UIView 的新功能一样使用它。
// Setup methods
/*
* FULL SCREEN Video Background with Background Mode None.
* Apply on ViewDidLoad
*/
- (void) setBackGroundVideo:(NSString *)videoPath withRepeat:(BOOL)repeat withOverlayColor:(UIColor *)color andAlpha:(CGFloat)alpha;
/*
* FULL SCREEN Video Background with Background Mode Custom
* Apply on ViewDidLoad
*/
- (void) setBackGroundVideo:(NSString *)videoPath withRepeat:(BOOL)repeat withOverlayColor:(UIColor *)color andAlpha:(CGFloat)alpha andBackgroundScalingMode:(CROCOVideoBackgroundModes) backgroundMode;
/*
* FULL SCREEN Video Background with Background Mode Custom and Custom Frame
* IMPORTANT: Apply on ViewDidAppear
*/
- (void) setBackGroundVideo:(NSString *)videoPath withRepeat:(BOOL)repeat withOverlayColor:(UIColor *)color andAlpha:(CGFloat)alpha andBackgroundScalingMode:(CROCOVideoBackgroundModes) backgroundMode andFrame:(CGRect)frame;
// Interaction methods if needed
- (void)play;
- (void)stop;
- (void)pause;
- (void)restart;
[self.viewVideoBackground setBackGroundVideo:@"CrocoVideo" withRepeat:YES withOverlayColor:[UIColor blackColor] andAlpha:0.7 andBackgroundScalingMode:CROCOVideoBackgroundModeAspectFill];
typedef NS_ENUM(NSInteger, CROCOVideoBackgroundModes) {
CROCOVideoBackgroundModeNone, // No scaling
CROCOVideoBackgroundModeAspectFit, // Uniform scale until one dimension fits
CROCOVideoBackgroundModeAspectFill, // Uniform scale until the movie fills the visible bounds. One dimension may have clipped contents
CROCOVideoBackgroundModeFill // Non-uniform scale. Both render dimensions will exactly match the visible bounds
};