This repository was archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathUIView+SLKAdditions.m
70 lines (59 loc) · 2.68 KB
/
UIView+SLKAdditions.m
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
//
// SlackTextViewController
// https://github.com/slackhq/SlackTextViewController
//
// Copyright 2014-2016 Slack Technologies, Inc.
// Licence: MIT-Licence
//
#import "UIView+SLKAdditions.h"
#import "SLKUIConstants.h"
@implementation UIView (SLKAdditions)
- (void)slk_animateLayoutIfNeededWithBounce:(BOOL)bounce options:(UIViewAnimationOptions)options animations:(void (^)(void))animations
{
[self slk_animateLayoutIfNeededWithBounce:bounce options:options animations:animations completion:NULL];
}
- (void)slk_animateLayoutIfNeededWithBounce:(BOOL)bounce options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
{
NSTimeInterval duration = bounce ? 0.65 : 0.2;
[self slk_animateLayoutIfNeededWithDuration:duration bounce:bounce options:options animations:animations completion:completion];
}
- (void)slk_animateLayoutIfNeededWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
{
if (bounce) {
[UIView animateWithDuration:duration
delay:0.0
usingSpringWithDamping:0.7
initialSpringVelocity:0.7
options:options
animations:^{
[self layoutIfNeeded];
if (animations) {
animations();
}
}
completion:completion];
}
else {
[UIView animateWithDuration:duration
delay:0.0
options:options
animations:^{
[self layoutIfNeeded];
if (animations) {
animations();
}
}
completion:completion];
}
}
- (NSArray *)slk_constraintsForAttribute:(NSLayoutAttribute)attribute
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d", attribute];
return [self.constraints filteredArrayUsingPredicate:predicate];
}
- (NSLayoutConstraint *)slk_constraintForAttribute:(NSLayoutAttribute)attribute firstItem:(id)first secondItem:(id)second
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d AND firstItem = %@ AND secondItem = %@", attribute, first, second];
return [[self.constraints filteredArrayUsingPredicate:predicate] firstObject];
}
@end