星空网 > 软件开发 > 操作系统

【代码笔记】电影上的花絮,自动滚动

一,效果图。

【代码笔记】电影上的花絮,自动滚动images/loading.gif' data-original="http://images2015.cnblogs.com/blog/337518/201510/337518-20151015134131085-1533583776.jpg" width="218" height="400" />

二,工程图。

【代码笔记】电影上的花絮,自动滚动

三,代码。

RootViewController.h

【代码笔记】电影上的花絮,自动滚动
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UIScrollViewDelegate>{  UIScrollView *scoreView;}@end
【代码笔记】电影上的花絮,自动滚动

 

RootViewController.m

【代码笔记】电影上的花絮,自动滚动
#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  if (self) {    // Custom initialization  }  return self;}- (void)viewDidLoad{  [super viewDidLoad];  // Do any additional setup after loading the view.    [self initBackgroundView];}#pragma -mark -functions-(void)initBackgroundView{  self.view.backgroundColor=[UIColor greenColor];    scoreView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 100, 320, 140)];  scoreView.backgroundColor=[UIColor greenColor];  scoreView.contentSize=CGSizeMake(320*3, 140);  scoreView.showsVerticalScrollIndicator=NO;  scoreView.showsHorizontalScrollIndicator=NO;  scoreView.scrollEnabled=NO;  scoreView.delegate=self;  [self.view addSubview:scoreView];      for (int i=0; i<4; i++) {    UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(i*320, 0, 320, 140)];     imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]];    if (i==3) {      imageView.image=[UIImage imageNamed:@"0.jpg"];    }    [scoreView addSubview:imageView];  }    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timer:) userInfo:nil repeats:YES];      UIPageControl* pc = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 220, 320, 20)];  pc.numberOfPages = 3;  pc.tag=100;  [pc addTarget:self action:@selector(pc:) forControlEvents:UIControlEventTouchUpInside];  [self.view addSubview:pc];  }-(void)timer:(NSTimer *)timer{  if (scoreView.contentOffset.x==320*3) {    scoreView.contentOffset=CGPointMake(0, 0);  }  [scoreView setContentOffset:CGPointMake(scoreView.contentOffset.x+320,0) animated:YES];}- (void)pc:(UIPageControl*)pc{  scoreView.contentOffset=CGPointMake(pc.currentPage*320, 0);}#pragma -mark -UIScrollerViewDelegate- (void)scrollViewDidScroll:(UIScrollView *)scrollView{  UIPageControl* pc = (UIPageControl*)[self.view viewWithTag:100];  pc.currentPage = scrollView.contentOffset.x / 320;  if (scoreView.contentOffset.x==320*3) {    pc.currentPage=0;  }}- (void)didReceiveMemoryWarning{  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}
【代码笔记】电影上的花絮,自动滚动

 




原标题:【代码笔记】电影上的花絮,自动滚动

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

fba运单:https://www.goluckyvip.com/tag/20260.html
fba运费:https://www.goluckyvip.com/tag/20261.html
fba运费标准:https://www.goluckyvip.com/tag/20262.html
fba运费表:https://www.goluckyvip.com/tag/20263.html
fba运费计算:https://www.goluckyvip.com/tag/20264.html
fba运费计算公式:https://www.goluckyvip.com/tag/20265.html
品牌出海新机遇,玩转“新兴”与“王牌”主题沙龙成功举办!:https://www.kjdsnews.com/a/1836370.html
每月资讯 | CBD为您带来最新行业动态:https://www.kjdsnews.com/a/1836371.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流