forked from Tricertops/KeepLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKPLExampleViewController.m
More file actions
80 lines (47 loc) · 1.86 KB
/
KPLExampleViewController.m
File metadata and controls
80 lines (47 loc) · 1.86 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
73
74
75
76
77
78
79
80
//
// KPLExampleViewController.m
// Keep Layout
//
// Created by Martin Kiss on 23.6.13.
// Copyright (c) 2013 Triceratops. All rights reserved.
//
#import "KPLExampleViewController.h"
#import "KeepLayout.h"
@interface KPLExampleViewController ()
@property (nonatomic, readwrite, strong) KPLExample *example;
@property (nonatomic, readwrite, strong) KPLExampleStateBlock exampleStateBlock;
@property (nonatomic, readwrite, assign) NSUInteger state;
@end
@implementation KPLExampleViewController
- (id)initWithExample:(KPLExample *)example {
self = [super initWithNibName:nil bundle:nil];
if (self) {
self.example = example;
self.title = self.example.title;
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(actionButtonTapped)];
self.navigationItem.rightBarButtonItem = actionButton;
}
return self;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor whiteColor];
self.view.clipsToBounds = YES;
self.exampleStateBlock = self.example.setupBlock(self);
if (self.exampleStateBlock) self.exampleStateBlock(self.state);
self.navigationItem.rightBarButtonItem.enabled = (self.exampleStateBlock != nil);
}
- (void)actionButtonTapped {
if ( ! self.exampleStateBlock) return;
self.state++;
[self.view keepAnimatedWithDuration:0.75
delay:0
usingSpringWithDamping:0.4
initialSpringVelocity:0.8
options:kNilOptions
layout:^{
self.exampleStateBlock(self.state);
}
completion:nil];
}
@end