ios开发ScrollView的用法小记

UIScrollView *scrollView = [[UIScrollView alloc]
initWithFrame:CGRectMake(0, 0, 320,
self.view.frame.size.height)];
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
for (int i = 0; i < 4; i++)
{
UIImageView *imageV = [[UIImageView alloc]
initWithFrame:CGRectMake(i * 320, 0, 320,
self.view.frame.size.height)];
imageV.image = [UIImage imageNamed:[NSString
stringWithFormat:@”%d.png”, i + 1]];
[scrollView addSubview:imageV];
[imageV release];
}
scrollView.contentSize = CGSizeMake(320 * 4,
self.view.frame.size.height);
//设置scrollView的代理 scrollView.delegate = self;
[self.view addSubview:scrollView]; [scrollView release];
//滑动scrollView时的回调函数 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@”scrollView滑动时执行的方法”);
}
- (void)scrollViewDidEndDragging:(UIScrollView
*)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@”手指离开scrollView时执行的方法”); }
- (void)scrollViewDidEndDecelerating:(UIScrollView
*)scrollView
{
NSLog(@”scrollView滑动结束后执行的方法”); }

你可能感兴趣的:(日记)