@interface ViewController : UIViewController<UIScrollViewDelegate>

{

UIScrollView * scrollView;

UIPageControl * pageControl;

//    BOOL pageControlIsChangingPage;

NSMutableArray * images;

}

//- (void)changePage:(id)sender;

- (void)setupPage;

@end

 
 
 
 

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.view.backgroundColor = [UIColor blackColor];

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];

pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 410, 320, 36)];

images = [NSMutableArray arrayWithObjects:@"h1.jpeg",@"h2.jpeg",@"h3.jpeg",@"h4.jpeg",@"h5.jpeg",@"h6.jpeg",@"h7.jpeg",@"h8.jpeg", nil];

[self.view addSubview:scrollView];

[self.view addSubview:pageControl];

[self setupPage];

}

////多余的方法

//- (void)changePage:(id)sender

//{

//

//    NSLog(@"%s",__func__);

//    CGRect frame = scrollView.frame;

//

//    frame.origin.x = frame.size.width * pageControl.currentPage;

//    frame.origin.y = 0;

//

//    [scrollView scrollRectToVisible:frame animated:YES];

//

//    pageControlIsChangingPage = YES;

//

//}

- (void)setupPage

{

NSLog(@"%s",__func__);

scrollView.delegate = self;

[scrollView setBackgroundColor: [UIColor blackColor]];

//

[scrollView setCanCancelContentTouches:NO];

scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite ;

//    //

//    scrollView.clipsToBounds  = YES;

//

//    scrollView.scrollEnabled = YES;

scrollView.pagingEnabled = YES;

//    //

//    scrollView.directionalLockEnabled = YES;

//

//隐藏滚动条

scrollView.alwaysBounceVertical = NO;

scrollView.alwaysBounceHorizontal = NO;

scrollView.showsHorizontalScrollIndicator = NO;

scrollView.showsVerticalScrollIndicator = NO;

NSInteger nimages = 0;

CGFloat cx = 0 ;//定义下一幅图片的的坐标

//循环导入图片

for(NSString * imagePath in images)

{

//        UIImageView * imageView = [[[UIImageView alloc] initWithFrame:CGRectZero]autorelease];

//

//        [imageView setBackgroundColor: [UIColor colorWithRed:.6 green:.6 blue:.6 alpha:1.0]];

//

//        UIImage * image = [UIImage imageNamed:imagePath];

//

//        [imageView setImage:image];

UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imagePath]];

CGRect rect = scrollView.frame;

rect.size.height = scrollView.frame.size.height;

rect.size.width = scrollView.frame.size.width;

rect.origin.x = cx;

rect.origin.y = 0;

imageView.frame = rect;

imageView.contentMode = UIViewContentModeScaleAspectFill;

[scrollView addSubview:imageView];

cx += scrollView.frame.size.width;

nimages ++;

}

//    //不必要的事件

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

pageControl.currentPage = 0;

pageControl.numberOfPages = nimages;

pageControl.tag = 0;

[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];

}

//scrollViewkai

- (void)scrollViewDidScroll:(UIScrollView *)_scrollView

{

NSLog(@"%s",__func__);

//    if(pageControlIsChangingPage)

//    {

//        return;

//    }

//画面拖动超过百分之五十进行切换

//返回page的值

CGFloat pageWidth = _scrollView.frame.size.width;

//函数名: floor  功 能: 返回小于或者等于指定表达式的最大整数

//函数名: ceil  功 能: 返回大于或者等于指定表达式的最小整数

int page = floor((_scrollView.contentOffset.x - pageWidth/2)/pageWidth)+1;

pageControl.currentPage = page;

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

NSLog(@"%s",__func__);

//    pageControlIsChangingPage = NO;

}

- (void)dealloc

{

[images release];

[scrollView release];

[pageControl release];

[super dealloc];

}

UIScrollView 与 UIPageView 的联合使用的更多相关文章

  1. Dynamics CRM 之ADFS 使用 WID 的独立联合服务器

    ADFS 的使用 WID 的独立联合服务器适用于自己的测试环境,常用的就是在虚机中使用. 拓扑图如下: wID:联合身份验证服务配置为使用 Windows 内部数据库

  2. Dynamics CRM 之ADFS 使用 WID 的联合服务器场

    使用 WID 的联合服务器场 默认拓扑 Active Directory 联合身份验证服务 (AD FS) 是联合服务器场,使用 Windows 内部数据库 (WID). 在这种拓扑, AD FS 使 ...

  3. 【原】Masonry+UIScrollView的使用注意事项

    [原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...

  4. Hibernate(5)—— 联合主键 、一对一关联关系映射(xml和注解) 和 领域驱动设计

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点总结如下: One to One 映射关系 一对一单向外键(XML/Annotation) 一对一双向外键关联(XML/A ...

  5. Federated Identity Pattern 联合身份模式

    Delegate authentication to an external identity provider. This pattern can simplify development, min ...

  6. [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合

    [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合 Datasets can often contain components of that require differe ...

  7. SQL联合查询:子表任一记录与主表联合查询

    今天有网友群里提了这样一个关于SQL联合查询的需求: 一.有热心网友的方案: 二.我的方案: select * from ( select a.*,(select top 1 Id from B as ...

  8. Dynamics CRM 之ADFS 使用 SQL Server 的联合服务器场

    此拓扑用于 Active Directory 联合身份验证服务 (AD FS) 不同于使用 Windows 内部数据库 (WID) 部署拓扑,因为不会将数据复制到每台联合服务器场中的联合身份验证服务器 ...

  9. Dynamics CRM 之ADFS 使用 WID 和代理的联合服务器场

    为此部署拓扑 Active Directory 联合身份验证服务 (AD FS) 等同于联合服务器场与 Windows 内部数据库 (WID) 拓扑中,但它将代理服务器计算机添加到外围网络,以支持外部 ...

随机推荐

  1. 徐汉彬:亿级Web系统搭建—单机到分布式集群

    当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的压力会越来越大,在这个过程中,我们会遇到很多的问题.为了解决这些性能压力带来问题,我们需要在Web系统架构层 ...

  2. UVa 836 - Largest Submatrix

    题目:给你一个n*n的01矩阵,求里面最大的1组成的矩形的米娜及. 分析:dp.单调队列.UVa 1330同题,仅仅是输入格式变了. 我们将问题分解成最大矩形.即求解以k行为底边的图形中的最大矩形.然 ...

  3. Git(一):Git与版本号控制简单介绍

    Intro 版本号控制系统是什么      版本号控制系统(Version Control System,VCS)能够帮助我们记录和跟踪项目中各文件内容的改动变化.它能够帮我们保存项目的各个版本号.以 ...

  4. stagefright框架(三)-选择Video Decode

    在<Stagefright (1) – Video Playback的流程>中,我们并没有详述Stagefright是如何根据影片档的类型来选择适合的video decoder,现在,就让 ...

  5. Median of Two Sorted Arrays(Java)

    求2个数组的中位数 方法很多 但是时间复杂度各异 1利用数组copy方法先融合两个数组,然后排序,找出中位数 import java.lang.reflect.Array; import java.u ...

  6. Mac系统杂项 (持续更新)

    一.调整LaunchPad的图标显示列数和行数 .调整每一列显示图标数量.在我的电脑上(1366 * 768),每列7个个人觉得比较不错 defaults write com.apple.dock s ...

  7. Octet string 解析

    百度百科的 ASN.1 http://baike.baidu.com/view/26378.htm 什么是 octet string 结构化字节 怎么解析,这里有微软的解析方法 If the byte ...

  8. mysql查询优化技巧

    索引优化,查询优化,查询缓存,服务器设置优化,操作系统和硬件优化,应用层面优化(web服务器,缓存)等等.这里记录的优化技巧更适合开发人员,都是从网络上搜集和整理的,主要是查询语句上的优化,其他层面上 ...

  9. has leaked ServiceConnection com.baidu.location.LocationClient

    02-06 05:01:52.806: E/ActivityThread(1120): Activity com.project.xxxActivity $1@45fc5af8 that was or ...

  10. js分页代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xh ...