首页 > 代码库 > 简单相册的实现
简单相册的实现
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height)]; scrollView.tag = 100; scrollView.contentSize = CGSizeMake(320 * 6, [UIScreen mainScreen].bounds.size.height); scrollView.delegate = self; scrollView.pagingEnabled = YES; scrollView.showsHorizontalScrollIndicator = NO; [self.view addSubview:scrollView]; [scrollView release]; for (int i = 0; i < 6; i++) { UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(i * 320, 0, 320, 568)]; scroll.maximumZoomScale = 4.0; scroll.minimumZoomScale = 1; scroll.delegate = self; scroll.tag = 110 + i; [scrollView addSubview:scroll]; [scroll release]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)]; imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d",i + 1] ofType:@"jpg"]]; imageView.tag = 101 + i; [scroll addSubview:imageView]; [imageView release]; } UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(10, 528, 300, 20)]; pageControl.tag = 120; pageControl.numberOfPages = 6; pageControl.pageIndicatorTintColor = [UIColor grayColor]; pageControl.currentPageIndicatorTintColor = [UIColor greenColor]; pageControl.currentPage = 0; [pageControl addTarget:self action:@selector(handlePageControl:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:pageControl]; [pageControl release]; } //设置缩放 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { switch (scrollView.tag) { case 110: return [scrollView viewWithTag:101]; case 111: return [scrollView viewWithTag:102]; case 112: return [scrollView viewWithTag:103]; case 113: return [scrollView viewWithTag:104]; case 114: return [scrollView viewWithTag:105]; case 115: return [scrollView viewWithTag:106]; default: break; } return nil; } //滑动pageControl - (void)handlePageControl:(UIPageControl *)pageControl { UIScrollView *scrollView =(UIScrollView *) [self.view viewWithTag:100]; [scrollView setContentOffset:CGPointMake(320 * pageControl.currentPage, 0) animated:YES]; } //恢复原图大小 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { switch (scrollView.tag) { case 100:{ UIPageControl *pageControl =(UIPageControl *) [self.view viewWithTag:120]; pageControl.currentPage = scrollView.contentOffset.x / 320; for (UIScrollView *scroll in scrollView.subviews) { if ([scroll isKindOfClass:[UIScrollView class]]) { [scroll setZoomScale:1.0]; } } } break; default: break; } }
简单相册的实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。