- (void)loadView
{
self.view=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]autorelease];
self.title=self.detailTitle;
/*
textField=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 30)];
textField.borderStyle=UITextBorderStyleRoundedRect;
[self.view addSubview:textField];
[textField release];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(100, 150, 100, 30);
[btn setTitle:@"change" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(changeTitle:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
*/
UIScrollView *_scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 416)];
_scrollView.contentSize=CGSizeMake(320*3, _scrollView.frame.size.height);
[self.view addSubview:_scrollView];
_scrollView.backgroundColor=[UIColor redColor];
_scrollView.delegate=self;
//自动分页 分页模式打开
_scrollView.pagingEnabled=YES;
[_scrollView release];
_pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake((320-100)/2, 300-30 , 100, 30)];
//当前页属性 currentPage
_pageControl.currentPage=0;
_pageControl.numberOfPages=3;//页数
[self.view addSubview:_pageControl];
}
#pragma mark-UIScrollView-
//只要滚动就执行
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// int _currenPage=_scrollView.contentOffset.x
// _pageControl.currentPage=_currenPage;
}
//刚开始拖拽的时候执行
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"%s",__FUNCTION__);
}
//拖拽结束的时候执行
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
NSLog(@"%s",__FUNCTION__);
}
//刚开始减速的时候执行
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"%s",__FUNCTION__);
}
//完成减速的时候执行
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
}
//只要滚动就执行
-(void)changeTitle:(id)sender
{
[self.delegate changeTitle:textField.text InViewController:self];
[self.navigationController popViewControllerAnimated:YES];
}
UIScrollView 基本用法
最新推荐文章于 2022-08-25 15:20:34 发布