This repository was archived by the owner on Apr 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathINKWelcomeViewController.m
98 lines (77 loc) · 3.66 KB
/
INKWelcomeViewController.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// INKWelcomeViewController.h
// ThatPDF
//
// Created by Brett van Zuiden on 8/8/13.
// Copyright (c) 2013 Ink. All rights reserved.
//
#import "INKWelcomeViewController.h"
@interface INKWelcomeViewController ()
@end
CGFloat const scrollViewHeight = 578.f;
CGFloat const scrollViewMargin = 0.f;
NSString *nsuserdefaultsHasRunFlowKeyName = @"com.inkmobility.hasRunWelcomeFlow";
@implementation INKWelcomeViewController
@synthesize pageScrollView;
+ (BOOL) shouldRunWelcomeFlow {
//You should run if not yet run
return ![[NSUserDefaults standardUserDefaults] boolForKey:nsuserdefaultsHasRunFlowKeyName];
}
+ (void) setShouldRunWelcomeFlow:(BOOL)should {
//ShouldRun is opposite of hasRun
[[NSUserDefaults standardUserDefaults] setBool:!should forKey:nsuserdefaultsHasRunFlowKeyName];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
CGFloat scrollViewWidth = self.view.bounds.size.width;
CGRect pageFrame = CGRectMake((self.view.bounds.size.width - scrollViewWidth), (self.view.bounds.size.height - scrollViewHeight), scrollViewWidth, scrollViewHeight);
pageScrollView = [pageScrollView initWithFrame:pageFrame];
NSString* appID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
NSMutableArray *views = [NSMutableArray arrayWithCapacity:4];
NSMutableArray *images = [NSMutableArray arrayWithObjects:@"OnboardStep2", @"OnboardStep3", nil];
if ([appID isEqualToString:@"com.inkmobility.ThatPhoto"]) {
[images insertObject:@"WelcomeThatPhoto" atIndex:0];
} else if ([appID isEqualToString:@"com.inkmobility.thatinbox"]) {
[images insertObject:@"WelcomeThatInbox" atIndex:0];
} else if ([appID isEqualToString:@"com.inkmobility.ThatPDF"]) {
[images insertObject:@"WelcomeThatPDF" atIndex:0];
} else if ([appID isEqualToString:@"com.inkmobility.thatcloud"]) {
[images insertObject:@"WelcomeThatCloud" atIndex:0];
}
for (NSString *imageName in images) {
UIView *welcomeScreen = [[UIView alloc] init];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
imageView.frame = CGRectMake(CGRectGetMidX(welcomeScreen.bounds) - CGRectGetMidX(imageView.bounds), 0, imageView.bounds.size.width, imageView.bounds.size.height);
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[welcomeScreen addSubview:imageView];
welcomeScreen.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
[views addObject:welcomeScreen];
}
[pageScrollView setScrollViewContents:views];
}
- (void) viewWillLayoutSubviews {
CGFloat scrollViewWidth = self.view.bounds.size.width;
CGRect pageFrame = CGRectMake((self.view.bounds.size.width - scrollViewWidth), (self.view.bounds.size.height - scrollViewHeight), scrollViewWidth, scrollViewHeight);
[self.pageScrollView setFrame:pageFrame];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)skipWelcomeFlow:(id)sender {
[INKWelcomeViewController setShouldRunWelcomeFlow:NO];
[self dismissViewControllerAnimated:YES completion:^{}];
}
@end