forked from slackhq/SlackTextViewController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIScrollView+SLKAdditions.m
More file actions
72 lines (59 loc) · 1.49 KB
/
Copy pathUIScrollView+SLKAdditions.m
File metadata and controls
72 lines (59 loc) · 1.49 KB
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
//
// SlackTextViewController
// https://github.com/slackhq/SlackTextViewController
//
// Copyright 2014-2016 Slack Technologies, Inc.
// Licence: MIT-Licence
//
#import "UIScrollView+SLKAdditions.h"
@implementation UIScrollView (SLKAdditions)
- (void)slk_scrollToTopAnimated:(BOOL)animated
{
if ([self slk_canScroll]) {
[self setContentOffset:CGPointZero animated:animated];
}
}
- (void)slk_scrollToBottomAnimated:(BOOL)animated
{
if ([self slk_canScroll]) {
[self setContentOffset:[self slk_bottomRect].origin animated:animated];
}
}
- (BOOL)slk_canScroll
{
if (self.contentSize.height > CGRectGetHeight(self.frame)) {
return YES;
}
return NO;
}
- (BOOL)slk_isAtTop
{
return CGRectGetMinY([self slk_visibleRect]) <= CGRectGetMinY(self.bounds);
}
- (BOOL)slk_isAtBottom
{
return CGRectGetMaxY([self slk_visibleRect]) >= CGRectGetMaxY([self slk_bottomRect]);
}
- (CGRect)slk_visibleRect
{
CGRect visibleRect;
visibleRect.origin = self.contentOffset;
visibleRect.size = self.frame.size;
return visibleRect;
}
- (CGRect)slk_bottomRect
{
return CGRectMake(0.0, self.contentSize.height - CGRectGetHeight(self.bounds), CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
}
- (void)slk_stopScrolling
{
if (!self.isDragging) {
return;
}
CGPoint offset = self.contentOffset;
offset.y -= 1.0;
[self setContentOffset:offset];
offset.y += 1.0;
[self setContentOffset:offset];
}
@end