-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIScrollView
93 lines (85 loc) · 3.62 KB
/
UIScrollView
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UIScrollView *scrollView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image = [UIImage imageNamed:@"mac.png"];
self.imageView = [[UIImageView alloc] initWithImage:image];//图片加入imageView
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 260)];//设置scrollView
[self.scrollView addSubview:self.imageView];//iamgeView加到scrollView里
self.scrollView.pagingEnabled = NO;//拖动时手指松开后图片时候继续滑行,no表示可以(这是自己的理解)
self.scrollView.contentSize = self.imageView.bounds.size;//scrollView里可滚动的空间,这里以imageView的大小为准
self.scrollView.delaysContentTouches = YES;//判断是否有拖动意图,yes时点一会再拖动,no则可以点上立刻拖动
self.scrollView.canCancelContentTouches = NO;//是否可以取消拖动意图,用户触摸一会后,yes可以再拖动,no则不可以再拖动
self.scrollView.bounces = YES;//用户拖动到边界后是否有回弹效果
self.scrollView.directionalLockEnabled = NO;//是否可以各方向拖动,yes时,当上下拖动时不能左右,左右时不能上下,斜着不受影响
self.scrollView.delegate = self;
[self.view addSubview:self.scrollView];
}
//只要滚动了就会触发
-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScroll");
NSLog(@"contentOffSet x is %f, y is %f",self.scrollView.contentOffset.x,self.scrollView.contentOffset.y);
self.scrollView.alpha = 0.5f;
}
//开始拖拽视图
-(void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDragging");
}
//完成拖拽
-(void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"scrollViewDidEndDragging");
self.scrollView.alpha = 1.0f;
}
//开始降速时
-(void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewWillBeginDecelerating");
}
//减速停止、手触摸时执行
-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidEndDecelerating");
self.scrollView.alpha = 1.0f;
}
//滚动动画停止时执行,代码改变时出发,也就是setContentOffset改变时
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndScrollingAnimation");
}
//设置放大缩小的视图,要是uiscrollview的subview
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
NSLog(@"viewForZoomingInScrollView");
return self.imageView;
}
//完成放大缩小时调用
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
{
self.imageView.frame=CGRectMake(50,0,100,400);
NSLog(@"scale between minimum and maximum. called after any 'bounce' animations");
}
//如果你不是完全滚动到滚轴视图的顶部,你可以轻点状态栏,那个可视的滚轴视图会一直滚动到顶部,那是默认行为,你可以通过该方法返回NO来关闭它
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewShouldScrollToTop");
return YES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidScrollToTop");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end