标签:interface import return 相册 super
MainViewController.h
#import <UIKit/UIKit.h> @interface MainViewController : UIViewController<UIScrollViewAccessibilityDelegate> @end
MainViewController.m
#import "MainViewController.h" @interface MainViewController () @end @implementation MainViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //UIScrollView的使用 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, 280, 350)]; scrollView.backgroundColor = [UIColor brownColor]; // scrollView.alpha = 0.3; [self.view addSubview:scrollView]; [scrollView release]; //scorllView的滚动范围 scrollView.contentSize = CGSizeMake(840, 0); //scorllView能否滚动 scrollView.scrollEnabled = YES; //是否可以迅速回到顶部 scrollView.scrollsToTop = YES; //点击状态栏迅速回到顶部 //scorllView按页翻动 scrollView.pagingEnabled = YES; //边缘的弹动效果 scrollView.bounces = YES; //scrollView的偏移量 scrollView.contentOffset = CGPointMake(0, 0); //默认为CGPonintMake(0,0) //scrollView的代理 scrollView.delegate = self; //设置scrollView的缩放 //1.设置缩放范围 scrollView.maximumZoomScale = 2.0; scrollView.minimumZoomScale = 0.5; //创建存放imageView的可缩放的scrollView1 UIScrollView *scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; scrollView1.delegate = self; scrollView1.maximumZoomScale = 2.0; scrollView1.minimumZoomScale = 0.5; [scrollView addSubview:scrollView1]; [scrollView1 release]; //创建存放imageView1的可缩放的scrollView2 UIScrollView *scrollView2 = [[UIScrollView alloc] initWithFrame:CGRectMake(280, 0, 280, 350)]; scrollView2.delegate = self; // scrollView2.backgroundColor = [UIColor redColor]; scrollView2.maximumZoomScale = 2.0; scrollView2.minimumZoomScale = 0.5; [scrollView addSubview:scrollView2]; [scrollView2 release]; //创建存放imageView2的可缩放的scrollView3 UIScrollView *scrollView3 = [[UIScrollView alloc] initWithFrame:CGRectMake(560, 0, 280, 350)]; scrollView3.delegate = self; // scrollView2.backgroundColor = [UIColor redColor]; scrollView3.maximumZoomScale = 2.0; scrollView3.minimumZoomScale = 0.5; [scrollView addSubview:scrollView3]; [scrollView3 release]; //创建3个imageView 分别将它们放在scrollView1、scrollView2、scrollView3上面 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; imageView.image = [UIImage imageNamed:@"1.jpg"]; imageView1.image = [UIImage imageNamed:@"2.jpg"]; imageView2.image = [UIImage imageNamed:@"3.jpg"]; [scrollView1 addSubview:imageView]; [scrollView2 addSubview:imageView1]; [scrollView3 addSubview:imageView2]; [imageView2 release]; [imageView1 release]; [imageView release]; } //缩放的设置:2 指定一个scrollView的子视图,跟着scrollView缩放 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return [scrollView.subviews firstObject]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //只要用户滚动scrollView,都会调用这个方法**************重要的 NSLog(@"任何偏移量的改变都会调用这个方法"); } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { //用户将要开始拖动scrollView的时候 NSLog(@"开始拖动"); } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { NSLog(@"结束拖动"); } - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { NSLog(@"开始减速"); } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { NSLog(@"结束减速"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
本文出自 “小刘_Blog” 博客,请务必保留此出处http://liuyafang.blog.51cto.com/8837978/1548575
标签:interface import return 相册 super
原文地址:http://liuyafang.blog.51cto.com/8837978/1548575