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; //创建存放p_w_picpathView的可缩放的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]; //创建存放p_w_picpathView1的可缩放的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]; //创建存放p_w_picpathView2的可缩放的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个p_w_picpathView 分别将它们放在scrollView1、scrollView2、scrollView3上面 UIImageView *p_w_picpathView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; UIImageView *p_w_picpathView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; UIImageView *p_w_picpathView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 350)]; p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:@"1.jpg"]; p_w_picpathView1.p_w_picpath = [UIImage p_w_picpathNamed:@"2.jpg"]; p_w_picpathView2.p_w_picpath = [UIImage p_w_picpathNamed:@"3.jpg"]; [scrollView1 addSubview:p_w_picpathView]; [scrollView2 addSubview:p_w_picpathView1]; [scrollView3 addSubview:p_w_picpathView2]; [p_w_picpathView2 release]; [p_w_picpathView1 release]; [p_w_picpathView 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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。