IPhone 之 UIPageControl,UIScrollView 分页

1. ScrollDemoViewController.h

 

#import <UIKit/UIKit.h>

@interface ScrollDemoViewController : UIViewController<UIScrollViewDelegate> {
	IBOutlet UIPageControl *pageControl;
	IBOutlet UIScrollView *ScrollView;
	
	IBOutlet UIView *view1;
	IBOutlet UIView *view2;
	IBOutlet UIView *view3;
}

@property(nonatomic,retain)UIView *view1;
@property(nonatomic,retain)UIView *view2;
@property(nonatomic,retain)UIView *view3;

@property(nonatomic,retain)UIPageControl *pageControl;

@property(nonatomic,retain)UIScrollView *scrollView;

-(IBAction)pageClick:(id)send;

@end

 

2. ScrollDemoViewController.m文件中添加如下代码:   

- (void)viewDidLoad {

    [super viewDidLoad];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width*3, scrollView.frame.size.height);
}

-(void)pageClick:(id)send{
	CGRect rect = CGRectMake([pageControl currentPage] * scrollView.frame.size.width, 0, 
							 scrollView.frame.size.width, scrollView.frame.size.height);
	[scrollView scrollRectToVisible:rect animated:YES];
    [view1 setHidden:YES ];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView1
{
	CGPoint offsetofScrollView = scrollView1.contentOffset;
	[pageControl setCurrentPage:offsetofScrollView.x / scrollView.frame.size.width];
}

- (void)dealloc {
	[pageControl release];
	[scrollView release];
	[view1 release];
	[view2 release];
	[view3 release];
    [super dealloc];
}

 

3. ScrollDemoViewController.xib文件如下添加控件:

 


IPhone 之 UIPageControl,UIScrollView 分页

 

设置scroll view 的paging Enabled 为选中状态即可

 


IPhone 之 UIPageControl,UIScrollView 分页

 

 

 

 

 

 

 

你可能感兴趣的:(Objective-C,分页,iPhone,uiscrollview,UIPageControl)