Skip to content

Commit a723596

Browse files
author
Felipe Plets
authored
Merge pull request #183 from felipeplets/master
Change SkipButton Height to 35 so it gets vertically centralized with PageControl
2 parents fd44e44 + e7b9d0e commit a723596

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

Source/OnboardingViewController.m

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static CGFloat const kPageControlHeight = 35;
1515
static CGFloat const kSkipButtonWidth = 100;
16-
static CGFloat const kSkipButtonHeight = 44;
16+
static CGFloat const kSkipButtonHeight = 35;
1717
static CGFloat const kBackgroundMaskAlpha = 0.6;
1818
static CGFloat const kDefaultBlurRadius = 20;
1919
static CGFloat const kDefaultSaturationDeltaFactor = 1.8;
@@ -53,7 +53,7 @@ - (instancetype)initWithBackgroundImage:(UIImage *)backgroundImage contents:(NSA
5353
}
5454

5555
self.backgroundImage = backgroundImage;
56-
56+
5757
return self;
5858
}
5959

@@ -72,7 +72,7 @@ - (instancetype)initWithBackgroundVideoURL:(NSURL *)backgroundVideoURL contents:
7272
}
7373

7474
self.videoURL = backgroundVideoURL;
75-
75+
7676
return self;
7777
}
7878

@@ -85,21 +85,21 @@ - (instancetype)initWithContents:(NSArray *)contents {
8585
if (!self) {
8686
return nil;
8787
}
88-
88+
8989
// Store the passed in view controllers array
9090
self.viewControllers = contents;
91-
91+
9292
// Set the default properties
9393
self.shouldMaskBackground = YES;
9494
self.shouldBlurBackground = NO;
9595
self.shouldFadeTransitions = NO;
9696
self.fadePageControlOnLastPage = NO;
9797
self.fadeSkipButtonOnLastPage = NO;
9898
self.swipingEnabled = YES;
99-
99+
100100
self.allowSkipping = NO;
101101
self.skipHandler = ^{};
102-
102+
103103
// Create the initial exposed components so they can be customized
104104
self.pageControl = [UIPageControl new];
105105
self.pageControl.numberOfPages = self.viewControllers.count;
@@ -109,7 +109,7 @@ - (instancetype)initWithContents:(NSArray *)contents {
109109
[self.skipButton setTitle:kSkipButtonText forState:UIControlStateNormal];
110110
[self.skipButton addTarget:self action:@selector(handleSkipButtonPressed) forControlEvents:UIControlEventTouchUpInside];
111111
self.skipButton.titleLabel.adjustsFontSizeToFitWidth = YES;
112-
112+
113113
return self;
114114
}
115115

@@ -120,14 +120,14 @@ - (void)viewDidLoad {
120120
[super viewDidLoad];
121121

122122
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAppEnteredForeground) name:UIApplicationDidBecomeActiveNotification object:nil];
123-
123+
124124
// now that the view has loaded, we can generate the content
125125
[self generateView];
126126
}
127127

128128
- (void)viewWillAppear:(BOOL)animated {
129129
[super viewWillAppear:animated];
130-
130+
131131
// if we have a video URL, start playing
132132
if (self.videoURL) {
133133
[self.player play];
@@ -162,13 +162,13 @@ - (void)generateView {
162162
self.pageVC.view.backgroundColor = [UIColor whiteColor];
163163
self.pageVC.delegate = self;
164164
self.pageVC.dataSource = self.swipingEnabled ? self : nil;
165-
165+
166166
if (self.shouldBlurBackground) {
167167
[self blurBackground];
168168
}
169-
169+
170170
UIImageView *backgroundImageView;
171-
171+
172172
// create the background image view and set it to aspect fill so it isn't skewed
173173
if (self.backgroundImage) {
174174
backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
@@ -177,7 +177,7 @@ - (void)generateView {
177177
[backgroundImageView setImage:self.backgroundImage];
178178
[self.view addSubview:backgroundImageView];
179179
}
180-
180+
181181
// as long as the shouldMaskBackground setting hasn't been set to NO, we want to
182182
// create a partially opaque view and add it on top of the image view, so that it
183183
// darkens it a bit for better contrast
@@ -196,40 +196,40 @@ - (void)generateView {
196196

197197
// set the initial current page as the first page provided
198198
_currentPage = [self.viewControllers firstObject];
199-
199+
200200
// more page controller setup
201201
[self.pageVC setViewControllers:@[self.currentPage] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
202202
self.pageVC.view.backgroundColor = [UIColor clearColor];
203203
[self addChildViewController:self.pageVC];
204204
[self.view addSubview:self.pageVC.view];
205205
[self.pageVC didMoveToParentViewController:self];
206206
[self.pageVC.view sendSubviewToBack:backgroundMaskView];
207-
207+
208208
// send the background image view to the back if we have one
209209
if (backgroundImageView) {
210210
[self.pageVC.view sendSubviewToBack:backgroundImageView];
211211
}
212-
212+
213213
// otherwise send the video view to the back if we have one
214214
else if (self.videoURL) {
215215
self.player = [[AVPlayer alloc] initWithURL:self.videoURL];
216216

217217
self.moviePlayerController = [AVPlayerViewController new];
218218
self.moviePlayerController.player = self.player;
219219
self.moviePlayerController.showsPlaybackControls = NO;
220-
220+
221221
[self.pageVC.view addSubview:self.moviePlayerController.view];
222222
[self.pageVC.view sendSubviewToBack:self.moviePlayerController.view];
223223
}
224-
224+
225225
// create the page control
226226
[self.view addSubview:self.pageControl];
227-
227+
228228
// if we allow skipping, setup the skip button
229229
if (self.allowSkipping) {
230230
[self.view addSubview:self.skipButton];
231231
}
232-
232+
233233
// if we want to fade the transitions, we need to tap into the underlying scrollview
234234
// so we can set ourself as the delegate, this is sort of hackish but the only current
235235
// solution I am aware of using a page view controller
@@ -300,7 +300,7 @@ - (void)pageViewController:(UIPageViewController *)pageViewController didFinishA
300300
if (!completed) {
301301
return;
302302
}
303-
303+
304304
// get the view controller we are moving towards, then get the index, then set it as the current page
305305
// for the page control dots
306306
UIViewController *viewController = [pageViewController.viewControllers lastObject];
@@ -310,7 +310,7 @@ - (void)pageViewController:(UIPageViewController *)pageViewController didFinishA
310310

311311
- (void)moveNextPage {
312312
NSUInteger indexOfNextPage = [self.viewControllers indexOfObject:_currentPage] + 1;
313-
313+
314314
if (indexOfNextPage < self.viewControllers.count) {
315315
[self.pageVC setViewControllers:@[self.viewControllers[indexOfNextPage]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
316316
[self.pageControl setCurrentPage:indexOfNextPage];
@@ -336,7 +336,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
336336
// scrollview's offset and the width of the screen
337337
CGFloat percentComplete = fabs(scrollView.contentOffset.x - self.view.frame.size.width) / self.view.frame.size.width;
338338
CGFloat percentCompleteInverse = 1.0 - percentComplete;
339-
339+
340340
// these cases have some funky results given the way this method is called, like stuff
341341
// just disappearing, so we want to do nothing in these cases
342342
if (percentComplete == 0) {
@@ -346,15 +346,15 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
346346
// set the next page's alpha to be the percent complete, so if we're 90% of the way
347347
// scrolling towards the next page, its content's alpha should be 90%
348348
[_upcomingPage updateAlphas:percentComplete];
349-
349+
350350
// set the current page's alpha to the difference between 100% and this percent value,
351351
// so we're 90% scrolling towards the next page, the current content's alpha sshould be 10%
352352
[_currentPage updateAlphas:percentCompleteInverse];
353353

354354
// determine if we're transitioning to or from our last page
355355
BOOL transitioningToLastPage = (_currentPage != self.viewControllers.lastObject && _upcomingPage == self.viewControllers.lastObject);
356356
BOOL transitioningFromLastPage = (_currentPage == self.viewControllers.lastObject) && (_upcomingPage == self.viewControllers[self.viewControllers.count - 2]);
357-
357+
358358
// fade the page control to and from the last page
359359
if (self.fadePageControlOnLastPage) {
360360
if (transitioningToLastPage) {
@@ -391,13 +391,13 @@ - (void)blurBackground {
391391
NSLog (@"*** error: image must be backed by a CGImage: %@", self.backgroundImage);
392392
return;
393393
}
394-
394+
395395
UIColor *tintColor = [UIColor colorWithWhite:0.7 alpha:0.3];
396396
CGFloat blurRadius = kDefaultBlurRadius;
397397
CGFloat saturationDeltaFactor = kDefaultSaturationDeltaFactor;
398398
CGRect imageRect = { CGPointZero, self.backgroundImage.size };
399399
UIImage *effectImage = self.backgroundImage;
400-
400+
401401
BOOL hasBlur = blurRadius > __FLT_EPSILON__;
402402
BOOL hasSaturationChange = fabs(saturationDeltaFactor - 1.) > __FLT_EPSILON__;
403403
if (hasBlur || hasSaturationChange) {
@@ -406,21 +406,21 @@ - (void)blurBackground {
406406
CGContextScaleCTM(effectInContext, 1.0, -1.0);
407407
CGContextTranslateCTM(effectInContext, 0, -self.backgroundImage.size.height);
408408
CGContextDrawImage(effectInContext, imageRect, self.backgroundImage.CGImage);
409-
409+
410410
vImage_Buffer effectInBuffer;
411411
effectInBuffer.data = CGBitmapContextGetData(effectInContext);
412412
effectInBuffer.width = CGBitmapContextGetWidth(effectInContext);
413413
effectInBuffer.height = CGBitmapContextGetHeight(effectInContext);
414414
effectInBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectInContext);
415-
415+
416416
UIGraphicsBeginImageContextWithOptions(self.backgroundImage.size, NO, [[UIScreen mainScreen] scale]);
417417
CGContextRef effectOutContext = UIGraphicsGetCurrentContext();
418418
vImage_Buffer effectOutBuffer;
419419
effectOutBuffer.data = CGBitmapContextGetData(effectOutContext);
420420
effectOutBuffer.width = CGBitmapContextGetWidth(effectOutContext);
421421
effectOutBuffer.height = CGBitmapContextGetHeight(effectOutContext);
422422
effectOutBuffer.rowBytes = CGBitmapContextGetBytesPerRow(effectOutContext);
423-
423+
424424
if (hasBlur) {
425425
// A description of how to compute the box kernel width from the Gaussian
426426
// radius (aka standard deviation) appears in the SVG spec:
@@ -469,40 +469,40 @@ - (void)blurBackground {
469469
if (!effectImageBuffersAreSwapped)
470470
effectImage = UIGraphicsGetImageFromCurrentImageContext();
471471
UIGraphicsEndImageContext();
472-
472+
473473
if (effectImageBuffersAreSwapped)
474474
effectImage = UIGraphicsGetImageFromCurrentImageContext();
475475
UIGraphicsEndImageContext();
476476
}
477-
477+
478478
// Set up output context.
479479
UIGraphicsBeginImageContextWithOptions(self.backgroundImage.size, NO, [[UIScreen mainScreen] scale]);
480480
CGContextRef outputContext = UIGraphicsGetCurrentContext();
481481
CGContextScaleCTM(outputContext, 1.0, -1.0);
482482
CGContextTranslateCTM(outputContext, 0, -self.backgroundImage.size.height);
483-
483+
484484
// Draw base image.
485485
CGContextDrawImage(outputContext, imageRect, self.backgroundImage.CGImage);
486-
486+
487487
// Draw effect image.
488488
if (hasBlur) {
489489
CGContextSaveGState(outputContext);
490490
CGContextDrawImage(outputContext, imageRect, effectImage.CGImage);
491491
CGContextRestoreGState(outputContext);
492492
}
493-
493+
494494
// Add in color tint.
495495
if (tintColor) {
496496
CGContextSaveGState(outputContext);
497497
CGContextSetFillColorWithColor(outputContext, tintColor.CGColor);
498498
CGContextFillRect(outputContext, imageRect);
499499
CGContextRestoreGState(outputContext);
500500
}
501-
501+
502502
// Output image is ready.
503503
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
504504
UIGraphicsEndImageContext();
505-
505+
506506
self.backgroundImage = outputImage;
507507
}
508508

0 commit comments

Comments
 (0)