Swift 2.0 自定义引导页

作者: xida0325 | 来源:发表于2015-12-05 14:15 被阅读115次

    //

    //LeadScrollView.swift

    //Tiger

    //

    //Created by admin on 15/12/5.

    //Copyright © 2015年xidaMM. All rights reserved.

    //

    importUIKit

    typealiasXDLeadScrollViewClosure = () ->Void

    classXDLeadScrollView:UIWindow,UIScrollViewDelegate{

    staticletshareInstance =XDLeadScrollView()

    varclosure:XDLeadScrollViewClosure!

    varscrollView:UIScrollView!

    varpageControl:UIPageControl!

    varimgsArray = [String]()

    varimgViewsArray = []

    varleadView:UIView!

    funccreateLeadView(){

    self.backgroundColor=kGlobalColor

    leadView=UIView(frame:CGRectMake(0,0,kScreenWidth,kScreenHeight+20))

    scrollView=UIScrollView(frame:CGRectMake(0,0,kScreenWidth,kScreenHeight+20))

    for(vari =0;i<4;i++) {

    self.imgsArray.append("Lead\(i+1)")

    }

    for(vari =0;i

    letimgView =UIImageView(frame:CGRectMake(CGFloat(i)*kScreenWidth,0,leadView.frame.size.width,leadView.frame.size.height))

    imgView.image=UIImage(named:imgsArray[i])

    self.scrollView.addSubview(imgView)

    }

    scrollView.contentSize=CGSizeMake(CGFloat(self.imgsArray.count)*kScreenWidth,0);

    scrollView.pagingEnabled=true

    scrollView.bounces=false

    scrollView.delegate=self

    scrollView.showsHorizontalScrollIndicator=false

    //下一步

    letbtnNext =UIButton(frame:CGRectMake(CGFloat(self.imgsArray.count)*kScreenWidth-kScreenWidth+80,kScreenHeight-80,200,50))

    //btnNext.backgroundColor = UIColor.redColor()

    btnNext.addTarget(self, action:"nextStep", forControlEvents:UIControlEvents.TouchUpInside)

    scrollView.addSubview(btnNext)

    self.pageControl=UIPageControl(frame:CGRectMake(0,kScreenHeight-25,kScreenWidth,30))

    self.pageControl.numberOfPages=self.imgsArray.count

    self.pageControl.currentPage=0

    self.pageControl.pageIndicatorTintColor=kGlobalColor

    self.pageControl.currentPageIndicatorTintColor=UIColor.whiteColor()

    self.pageControl.addTarget(self, action:"pageTurn:", forControlEvents:UIControlEvents.ValueChanged)

    //self.scrollView.addSubview(self.pageControl)

    self.leadView.addSubview(self.scrollView)

    //leadView.addSubview(self.pageControl)

    self.addSubview(self.leadView)

    }

    funcshow(){

    UIApplication.sharedApplication().delegate?.window!?.addSubview(self)

    self.makeKeyWindow()

    self.windowLevel=UIWindowLevelNormal

    self.hidden=false

    }

    funcclose(){

    self.hidden=true

    self.resignKeyWindow()

    self.closure()

    }

    funcnextStep()

    {

    UIView.animateWithDuration(0.6, animations: { () ->Voidin

    self.leadView.alpha=0

    XDUserDefaults.setBool(kKeyIsLoadLeadView, value:true)

    }) { (bool:Bool) ->Voidin

    self.close()

    }

    }

    funcpageTurn(sender:UIPageControl){

    letcontentOffsetX =kScreenWidth*CGFloat(sender.currentPage)

    scrollView.setContentOffset(CGPointMake(contentOffsetX,scrollView.frame.origin.y), animated:true)

    }

    funcscrollViewDidEndDecelerating(scrollView1:UIScrollView) {

    letoffset = scrollView1.contentOffset

    letbounds = scrollView1.frame

    UIView.animateWithDuration(0.3, animations: { () ->Voidin

    self.pageControl.currentPage=Int(offset.x/bounds.size.width)

    }, completion:nil)

    }

    // Only override drawRect: if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    //override func drawRect(rect: CGRect) {

    //// Drawing code

    //}

    }

    相关文章

      网友评论

        本文标题:Swift 2.0 自定义引导页

        本文链接:https://www.haomeiwen.com/subject/mbgshttx.html