小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

用定時(shí)器控制滾動(dòng)視圖UIScrollView

 久辰堡 2015-07-24

#import "SaleView.h"

#import "UIImageView+AFNetworking.h"

#define  SALEVIEWWIDTH  self.frame.size.width

#define  SALEVIEWHIGHT  self.frame.size.height

@interface SaleView()<UIScrollViewDelegate>

{

    //滾動(dòng)視圖

    UIScrollView * scrollView;

    //頁(yè)碼指示器

    UIPageControl * pageControl;

    NSString*imageStr;

    UIImageView*imageView;

    int timecount;

}

@end


@implementation SaleView

-(void)prepareScrollView;

{

    

    scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,SALEVIEWWIDTH,SALEVIEWHIGHT)];

      //設(shè)置默認(rèn)的第一張圖片

    imageStr=self.dataArr[0][@"ImgPath"];

    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, SALEVIEWWIDTH,SALEVIEWHIGHT)];

    [imageView setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:nil];

    [scrollView addSubview:imageView];

    

    //設(shè)置滾動(dòng)區(qū)域

    scrollView.contentSize = CGSizeMake(self.frame.size.width,SALEVIEWHIGHT);

    //設(shè)置分頁(yè),默認(rèn)為NO

    scrollView.pagingEnabled = YES;

    //關(guān)閉回彈

    scrollView.bounces = NO;

    //關(guān)閉滾動(dòng)條

    scrollView.showsHorizontalScrollIndicator = NO;

    scrollView.showsVerticalScrollIndicator=NO;

    //設(shè)置代理

    scrollView.delegate = self;

    //將滾動(dòng)視圖加到視圖上

    [self addSubview:scrollView];

    

    //這個(gè)控件叫做面碼指示器,用來(lái)提示頁(yè)碼

    pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(self.frame.size.width/2, 120,self.frame.size.width/2-80,30)];

    //設(shè)置總頁(yè)碼數(shù),也就告訴指示器有多少頁(yè),顯示多少個(gè)點(diǎn)

    pageControl.numberOfPages =self.dataArr.count;

    //設(shè)置當(dāng)前頁(yè)

    pageControl.currentPage =0;

    //設(shè)置指示器的顏色

    pageControl.pageIndicatorTintColor = [UIColor grayColor];

    pageControl.currentPageIndicatorTintColor = [UIColor redColor];

    //給頁(yè)碼指示器加響應(yīng)事件

    [pageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged];

     [self addSubview:pageControl];

    

    //使用NSTimer實(shí)現(xiàn)定時(shí)觸發(fā)滾動(dòng)控件滾動(dòng)的動(dòng)作。

    timecount=0;

    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scrollTimer) userInfo:nil repeats:YES];

}

//滾圖的動(dòng)畫(huà)效果

-(void)pageTurn:(UIPageControl *)aPageControl{

   long int whichPage = aPageControl.currentPage;

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:0.3f];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [scrollView setContentOffset:CGPointMake(self.frame.size.width * whichPage, 0.0f) animated:YES];

    [UIView commitAnimations];

}


//定時(shí)滾動(dòng)

-(void)scrollTimer

{

    self.flag=timecount+1;

   timecount++;

    if ( timecount==self.dataArr.count) {

                timecount = 0;

    }

    imageStr=_dataArr[timecount][@"ImgPath"];

    [imageView setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:nil];

    [scrollView reloadInputViews];

    pageControl.currentPage=timecount;

}



    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多