启动引导页

- (void)viewWillAppear:(BOOL)animated{

    if (![_userDefualtsboolForKey:@"intruduceAnimation"]) {

        IntrodutionView *intro = [[IntrodutionViewalloc]initWithFrame:self.tabBarController.view.bounds];

        [self.tabBarController.viewaddSubview:intro];

    }

}


IntrodutionView.h如下:

@interface IntrodutionView :UIView<UIScrollViewDelegate>



IntrodutionView.m如下:

#import "IntrodutionView.h"

#import "Constants.h"

#import "UIColor+Category.h"

#import <POP/POP.h>


@interface IntrodutionView ()

{

    UIScrollView *_sv;

    UIPageControl *_pageControl;

    NSInteger currentPage;

    UIView *page1;

    UIView *page2;

    UIView *page3;

    UIImageView *house;

    UIImageView *book;

    UIImageView *first;

    BOOL pageS;

    BOOL pageT;

}


@end




@implementation IntrodutionView



-(id)initWithFrame:(CGRect)frame{

    if (self = [superinitWithFrame:frame]) {

        pageS = YES;

        pageT = YES;

        [selfaddIntroduceView];

        [selfaddPageControll];

        self.backgroundColor = [UIColorwhiteColor];

        currentPage = 0;

        [selfpage1SetAnimate];

    }

    return self;

}


-(void)addIntroduceView{

    _sv = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,BOUNDS.size.width,BOUNDS.size.height)];

    NSLog(@"%f",BOUNDS.size.width);

    _sv.delegate =self;

    _sv.pagingEnabled =YES;

    _sv.bounces =NO;

    _sv.showsHorizontalScrollIndicator =NO;

    

    //    UIImageView *yuntu = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"3-21"]];

    //    yuntu.frame = CGRectMake(first.frame.origin.x + 150, 250, yuntu.image.size.width, yuntu.image.size.height);

    //    [page3 addSubview:yuntu];

    

    [_sv setContentSize:CGSizeMake(BOUNDS.size.width * 3, BOUNDS.size.height)];

    [selfaddSubview:_sv];

}


-(void)addPageControll{

    _pageControl = [[UIPageControlalloc]initWithFrame:CGRectMake(BOUNDS.size.width/2-100,BOUNDS.size.height-30,200,20)];

    _pageControl.currentPageIndicatorTintColor = [UIColorcolorWithHexString:@"#87d0f3"];

    _pageControl.pageIndicatorTintColor = [UIColorcolorWithHexString:@"#d2d2d2"];

    _pageControl.numberOfPages =3;

    //    _pageControl.backgroundColor = [UIColor greenColor];

    [_pageControladdTarget:selfaction:@selector(pageClick)forControlEvents:UIControlEventValueChanged];

    [selfaddSubview:_pageControl];

}



-(void)page3SetAnimate2{

    UIImageView *second = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"3-12"]];

    second.frame =CGRectMake(BOUNDS.size.width/2 - second.image.size.width/2,BOUNDS.size.height/2 - second.image.size.height/2 +10, second.image.size.width, second.image.size.height);

    second.alpha = 0;

    [page3 addSubview:second];

    

    UIImageView *yuntu = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"3-22"]];

    yuntu.frame = CGRectMake(first.frame.origin.x + 140, 324, yuntu.image.size.width, yuntu.image.size.height);

    yuntu.alpha = 0;

    [page3 addSubview:yuntu];

    

    [UIViewanimateWithDuration:0.8animations:^{

        second.alpha = 1;

        yuntu.alpha = 1;

    } completion:^(BOOL finished) {

        UIImageView *word = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"3-0"]];

        word.frame =CGRectMake(BOUNDS.size.width/2 - word.image.size.width/2, -100, word.image.size.width, word.image.size.height);

        [page3 addSubview:word];

        [selfslideWithView:wordFromValue:-word.image.size.heightToValue:130BeginTime:CACurrentMediaTime()PropertyName:kPOPLayerPositionYKey:@"AnimationScale"tension:0.1];

        

        UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

        if (IOS <7) {

            [btn setImage:[UIImageimageNamed:@"3-3"]forState:UIControlStateNormal];

        }else{

            [btn setImage:[[UIImageimageNamed:@"3-3"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];

        }

        

        btn.frame =CGRectMake(BOUNDS.size.width/2 - btn.imageView.image.size.width/2, second.frame.origin.y +second.frame.size.height +30, btn.imageView.image.size.width, btn.imageView.image.size.height);

        [btn addTarget:selfaction:@selector(enterClick)forControlEvents:UIControlEventTouchUpInside];   //按钮点击后,删掉当前引导视图,进入rootController

        btn.alpha = 0;

        [page3 addSubview:btn];

        [UIViewanimateWithDuration:1animations:^{

            btn.alpha = 1;

        }];

    }];

}


-(void)enterClick{

    NSUserDefaults *userDefaults = [NSUserDefaultsstandardUserDefaults];

    [userDefaults setBool:YESforKey:@"intruduceAnimation"];

    [userDefaults synchronize];

    for (UIView *vinpage1.subviews) {

        [v pop_removeAllAnimations];

    }

    for (UIView *vinpage2.subviews) {

        [v pop_removeAllAnimations];

    }

    for (UIView *vinpage3.subviews) {

        [v pop_removeAllAnimations];

    }

    [_svremoveFromSuperview];

    [_pageControlremoveFromSuperview];

    [selfremoveFromSuperview];

}



-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    [_pageControlupdateCurrentPageDisplay];

    if (currentPage ==1 &&pageS) {

        [selfpage2SetAnimate];

        pageS = NO;

    }

    if (currentPage ==2 &&pageT) {

        [selfpage3SetAnimate];

        pageT = NO;

    }

}



-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGFloat pageWidth = scrollView.bounds.size.width ;

    float fractionalPage = scrollView.contentOffset.x / pageWidth ;

    currentPage = lround(fractionalPage) ;

    

    if (_pageControl.currentPage !=currentPage)

    {

        _pageControl.currentPage =currentPage ;

        

        // if we are dragging, we want to update the page control directly during the drag

        if (scrollView.dragging)

            [_pageControlupdateCurrentPageDisplay] ;

    }

    

}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    [_pageControl updateCurrentPageDisplay];

    if (currentPage == 1 && pageS) {

        [self page2SetAnimate];

        pageS = NO;

    }

    if (currentPage == 2 && pageT) {

        [self page3SetAnimate];

        pageT = NO;

    }

}


-(void)slideWithView:(UIView *)view FromValue:(NSInteger)fromValue ToValue:(NSInteger)toValue BeginTime:(NSInteger)beginTime PropertyName:(NSString *)name Key:(NSString *)key tension:(NSInteger)tension{

    POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:name];

    anim.springSpeed = 0.2;

    anim.dynamicsTension = tension;

    anim.beginTime = beginTime;

    anim.springBounciness = 6;

    anim.springSpeed = 10;

    anim.fromValue = @(fromValue);

    anim.toValue = @(toValue);

    [view pop_addAnimation:anim forKey:key];

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值