Lottie 做引导动效
@implementation LGuidanceViewController
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
self.navigationController.navigationBar.alpha = 0;
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationController.navigationBar.alpha = 1;
}
- (void)loadView
{
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(kUIScreenWidth * kPageCount, 0);
scrollView.bounces = NO;
self.view = scrollView;
self.scrollView = scrollView;
self.scrollView.delegate = self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self addScrollImages];
}
- (void)addScrollImages
{
for (int i = 0; i < kPageCount; i++) {
// 1.显示图片
NSString *name = [NSString stringWithFormat:@"Welcomedata%d", i+1];
LOTAnimationView *animationView = [LOTAnimationView animationNamed:name];
// animationView.loopAnimation = YES;
// 2.设置frame
animationView.frame = CGRectMake(self.view.width * i, 0, self.view.width, self.view.height);
[self.scrollView addSubview:animationView];
if (i == 0) {
self.firtstAnimationView = animationView;
}
if (i == 1) {
self.secondAnimationView = animationView;
self.secondAnimationView.animationSpeed = 3;
}
if (i == 2) {
self.thirdanimationView = animationView;
}
UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake( (kUIScreenWidth - kPageControlWidth) / 2.0, kUIScreenHeight - 50, kPageControlWidth , kPageControlHeight)];
pageControl.numberOfPages = kPageCount;
pageControl.currentPage = i;
pageControl.currentPageIndicatorTintColor = kUIColorFromRGB(0x2D2D2D);
pageControl.pageIndicatorTintColor = kUIColorFromRGB(0xC4C4C4);
[animationView addSubview:pageControl];
[self animatedForPageOne];
if (i == kPageCount - 1) {
UIButton *enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
enterButton.frame = CGRectMake( (kUIScreenWidth - kStartBtnWidth) / 2.0, kUIScreenHeight -105, kStartBtnWidth, kStartBtnHeight);
enterButton.backgroundColor = [UIColor colorWithHexStr:@"0A93FF"];
[enterButton setTitle:@"立即体验" forState:UIControlStateNormal];
[enterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
enterButton.layer.cornerRadius = 30;
enterButton.layer.borderWidth = 1.2;
enterButton.titleLabel.font = [UIFont systemFontOfSize:16];
enterButton.layer.borderColor = [UIColor whiteColor].CGColor;
enterButton.layer.masksToBounds = YES;
//[enterButton setImage:[UIImage imageNamed:@"launch_experience"] forState:UIControlStateNormal];
[enterButton addTarget:self action:@selector(startBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[animationView addSubview:enterButton];
}
else
{
UIButton *skipButton = [UIButton buttonWithType:UIButtonTypeCustom];
skipButton.frame = CGRectMake(kUIScreenWidth - kSkipBtnWidth -20 , 20, kSkipBtnWidth, kSkipBtnHeight);
skipButton.backgroundColor = [UIColor clearColor];
[skipButton setTitle:@"跳过" forState:UIControlStateNormal];
[skipButton setTitleColor:kUIColorFromRGBA(0x000000, 0.3) forState:UIControlStateNormal];
// [skipButton setImage:[UIImage imageNamed:@"launch_skip"] forState:UIControlStateNormal];
[skipButton addTarget:self action:@selector(skipBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[animationView addSubview:skipButton];
}
}
}
-(void)skipBtnClicked
{
LPasswordLoginViewController * loginVC = [[LPasswordLoginViewController alloc]init];
[self.navigationController pushViewController:loginVC animated:YES];
// NSString * class = kSelectedClassID?kSelectedClassID:kClassID;
// if ([class integerValue]==0) {//未选择分类
// LSelectpositionViewController * selectVC = [[LSelectpositionViewController alloc]init];
// [self presentViewController:selectVC animated:YES completion:nil];
//
// }else{
// LTabBarViewController *mainVC = [[LTabBarViewController alloc]init];
// self.view.window.rootViewController = mainVC;
// }
}
- (void)startBtnClicked
{
LTabBarViewController *mainVC = [[LTabBarViewController alloc]init];
self.view.window.rootViewController = mainVC;
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
// [self playAnimition];
//}
//- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
//{
// [self playAnimition];
//}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int currentPage = floor((self.scrollView.contentOffset.x - kUIScreenWidth / 2) / kUIScreenWidth) + 1;
if (currentPage == kPageCount - 1) {
[self.thirdanimationView playToProgress:1 withCompletion:nil];
[UIView animateWithDuration:1.1 animations:^{
self.thirdanimationView.alpha = 1;
}];
}else if (currentPage == 0){
[self.firtstAnimationView playToProgress:1 withCompletion:nil];
[UIView animateWithDuration:1.1 animations:^{
self.firtstAnimationView.alpha = 1;
}];
}else{
[self.secondAnimationView playToProgress:1 withCompletion:nil];
[UIView animateWithDuration:1.1 animations:^{
self.secondAnimationView.alpha = 1;
}];
}
}
-(void)animatedForPageOne {
[self playAnimition];
}
- (void)playAnimition
{
[self.firtstAnimationView playToProgress:1 withCompletion:nil];
[UIView animateWithDuration:1.1 animations:^{
self.firtstAnimationView.alpha = 1;
}];
[self.secondAnimationView playToProgress:1 withCompletion:nil];
[UIView animateWithDuration:1.1 animations:^{
self.secondAnimationView.alpha = 1;
}];
[self.thirdanimationView playToProgress:1 withCompletion:nil];
[UIView animateWithDuration:1.1 animations:^{
self.thirdanimationView.alpha = 1;
}];
}记得命名image0 2image0 这种图片规范要符合