SKSplashView 是一个可以创建漂亮的动画启动视图的简单类,用于在不同视图之间过渡。在您的应用加载时,它是一个完美的启动界面。
启动视图允许您创建具有预设动画的动画背景视图,并提供添加将在启动视图动画期间持续动画的启动图标的选项。
如果通过 Cocoapods 安装不起作用或您不习惯使用它,您始终可以将 'SKSplashView' 文件夹拖放到您的项目中,并 #import "SKSplashView.h"
,然后就可以开始使用。
只需创建一个具有所需自定义选项的 SKSplashView 实例。
SKSplashView *splashView = [[SKSplashView alloc] initWithBackgroundColor:[UIColor blueColor] animationType:SKSplashAnimationTypeZoom];
//The SplashView can be initialized with a variety of animation types and backgrounds. See customizability for more.
splashView.animationDuration = 3.0f; //Set the animation duration (Default: 1s)
[self.view addSubview:splashView]; //Add the splash view to your current view
[splashView startAnimation]; //Call this method to start the splash animation
启动视图也可以使用以下方法进行初始化
- (instancetype)initWithAnimationType: (SKSplashAnimationType) animationType;
- (instancetype)initWithBackgroundColor: (UIColor *) backgroundColor animationType: (SKSplashAnimationType) animationType;
- (instancetype)initWithBackgroundImage: (UIImage *) backgroundImage animationType: (SKSplashAnimationType) animationType;
- (instancetype)initWithSplashIcon: (SKSplashIcon *)icon animationType: (SKSplashAnimationType) animationType;
- (instancetype) initWithSplashIcon:(SKSplashIcon *)icon backgroundColor: (UIColor *) backgroundColor animationType:(SKSplashAnimationType) animationType;
- (instancetype) initWithSplashIcon:(SKSplashIcon *)icon backgroundImage:(UIImage *) backgroundImage animationType:(SKSplashAnimationType) animationType;
可以使用以下属性自定义启动视图的外观
@property (strong, nonatomic) UIColor *backgroundViewColor; //Sets the background color of the splash view (Default: white)
@property (strong, nonatomic) UIImage *backgroundImage; //Sets a background image to the splash view
@property (nonatomic, assign) CGFloat animationDuration; //Sets the duration of the splash view
启动视图还允许您使用以下类型自定义启动视图的动画过渡
SKSplashAnimationTypeFade,
SKSplashAnimationTypeBounce,
SKSplashAnimationTypeShrink,
SKSplashAnimationTypeZoom,
SKSplashAnimationTypeNone,
SKSplashAnimationTypeCustom
除了添加动画启动视图外,您还可以添加图标,它具有自己的自定义选项并在启动视图运行期间动画化。要将启动图标添加到启动视图中
在展示启动视图的视图中 #import "SKSplashIcon.h"
以下是如何初始化启动视图
SKSplashIcon *splashIcon = [[SKSplashIcon alloc] initWithImage:[UIImage imageNamed:@"test.png"] animationType:SKIconAnimationTypeNone];
//Initialize with the customizability option of your choice. See Customizability for more.
在初始化启动视图时添加启动图标
SKSplashView *splashView = [SKSplashView alloc] initWithSplashIcon:splashIcon backgroundColor:splashColor animationType:SKSplashAnimationTypeFade];
您还可以使用以下方法在初始化启动视图时添加启动图标
- (instancetype)initWithSplashIcon: (SKSplashIcon *)icon animationType: (SKSplashAnimationType) animationType;
- (instancetype) initWithSplashIcon:(SKSplashIcon *)icon backgroundColor: (UIColor *) backgroundColor animationType:(SKSplashAnimationType) animationType;
- (instancetype) initWithSplashIcon:(SKSplashIcon *)icon backgroundImage:(UIImage *) backgroundImage animationType:(SKSplashAnimationType) animationType;
可以使用以下属性自定义启动图标的的外观
@property (strong, nonatomic) UIColor *iconColor; //Sets the icon color of the icon (Default: white)
@property (nonatomic, assign) CGSize iconSize; //Sets the size of the icon (Default: 60x60)
还可以使用以下动画类型自定义启动图标的动画
SKIconAnimationTypeBounce,
SKIconAnimationTypeGrow,
SKIconAnimationTypeShrink,
SKIconAnimationTypeFade,
SKIconAnimationTypePing,
SKIconAnimationTypeBlink,
SKIconAnimationTypeNone,
SKIconAnimationTypeCustom
您可以可选地将启动视图代理添加到视图控制器以监听启动视图开始和结束动画。为此
<SKSplashDelegate>
添加到你的接口中splashView.delegate = self;
- (void) splashView:(SKSplashView *)splashView didBeginAnimatingWithDuration:(float)duration
{
NSLog(@"Splash view started animating with duration %f", duration);
}
- (void) splashViewDidEndAnimating:(SKSplashView *)splashView
{
NSLog(@"Splash view stopped animating");
}
SKSplashView 允许你在执行网络请求时运行启动画面动画。当你的应用在启动时需要下载必要数据时,这非常理想。通过简单地调用
[splashView startAnimationWhileExecuting:request withCompletion:^(NSData *data, NSURLResponse *response, NSError *error) {}];
带有一个初始化的启动画面视图,启动画面动画将一直重复,直到你下载完所有必要的启动数据!
注意:目前该功能不允许直接动画化启动画面视图本身,但允许进行某些启动图标动画。
以下是一些使用 SKSplashView 创建的启动画面的示例(Twitter iOS 应用和 Ping iOS 应用)。所有示例代码都可在 演示中找到。如果你找到了使用 SKSplashView 模仿其他流行的 iOS 应用启动画面的方法,请让我知道,以便我可以将其添加到此处。
若要获取有关 SKSplashView 的更多信息,请查看 演示
如果你认为你可以改善或为 SKSplashView 增加更多可定制性,请随意提出问题/提交 PR。
如有任何问题,请通过 Twitter 指向我 @sachinkesiraju
SKSplashView 在 MIT 许可证下可用。有关更多信息,请参阅 许可证