您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。