1、UIScrollView
看代码吧。说的比较详细
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor = [UIColor redColor];
// 是否支持滑动最顶端
// scrollView.scrollsToTop = NO;
scrollView.delegate = self;
// 设置内容大小
scrollView.contentSize = CGSizeMake(320, 460*10);
// 是否反弹
// scrollView.bounces = NO;
// 是否分页
// scrollView.pagingEnabled = YES;
// 是否滚动
// scrollView.scrollEnabled = NO;
// scrollView.showsHorizontalScrollIndicator = NO;
// 设置indicator风格
// scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
// 设置内容的边缘和Indicators边缘
// scrollView.contentInset = UIEdgeInsetsMake(0, 50, 50, 0);
// scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 50, 0, 0);
// 提示用户,Indicators flash
[scrollView flashScrollIndicators];
// 是否同时运动,lock
scrollView.directionalLockEnabled = YES;
[self.view addSubview:scrollView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 320, 40)];
label.backgroundColor = [UIColor yellowColor];
label.text = @"学习scrolleview";
[scrollView addSubview:label];
[label release];
}
#pragma mark -
/*
// 返回一个放大或者缩小的视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
}
// 开始放大或者缩小
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:
(UIView *)view
{
}
// 缩放结束时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}
// 视图已经放大或缩小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
*/
// 是否支持滑动至顶部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
return YES;
}
// 滑动到顶部时调用该方法
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
// scrollView 已经滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScroll");
}
// scrollView 开始拖动
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDragging");
}
// scrollView 结束拖动
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"scrollViewDidEndDragging");
}
// scrollView 开始减速(以下两个方法注意与以上两个方法加以区别)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDecelerating");
}
// scrollview 减速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidEndDecelerating");
}
2、UIPageControl
// 初始化分页控件
self.myPageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(150, 210, 150, 30)];
self.myPageControl.backgroundColor=[UIColor grayColor];
// 设置总页数
self.myPageControl.numberOfPages=3;
// 指定当前也
// self.myPageControl.currentPage=1;
// 设置页面的颜色(当前页与其他页)
self.myPageControl.pageIndicatorTintColor=[UIColor redColor];
self.myPageControl.currentPageIndicatorTintColor=[UIColor greenColor];
[self.view addSubview:self.myPageControl];
3、视图跳转
MainViewController *mainVc=[[MainViewController alloc] init];
//模态视图 推入下一个页面
[self presentViewController:mainVc animated:YES completion:^{
NSLog(@"next");
}];
//[self presentViewController:mainVc animated:YES completion:nil;
//模态视图 返回上一页
[self dismissViewControllerAnimated:YES completion:nil];
}];
//切换风格
mainVc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
4、UINavigationController视图控制器容器
//初始化容器,并将容器设为根视图
FirstViewController *firstVc=[[FirstViewController alloc] init];
UINavigationController *navc=[[UINavigationController alloc] initWithRootViewController:firstVc];
self.window.rootViewController=navc;
//控制视图推进推出的主要方法如下:
pushViewController:viewController animated:BOOL
(加载视图控制器)
添加指定的视图控制器并予以显示
popViewControllerAnimated:BOOL
(推出当前视图控制器)
//弹出并向左显示前一个视图
//popToViewController:viewController animated:BOOL
(推到指定视图控制器)
//回到指定视图控制器, 也就是不只弹出一个
popToRootViewControllerAnimated:BOOL
//退到根视图控制器
setNavigationBarHidden:BOOL animated:BOOL
//这个可以研究的太多太多
//贴一个地址
//http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html