-
Notifications
You must be signed in to change notification settings - Fork 2
/
CustomModalPresentationController.m
54 lines (40 loc) · 1.89 KB
/
CustomModalPresentationController.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
//
// CustomModalPresentationController.m
// Soundrocket
//
// Created by Sebastian Boldt on 08.02.16.
// Copyright © 2016 sebastianboldt. All rights reserved.
//
#import "CustomModalPresentationController.h"
@implementation CustomModalPresentationController
-(instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController presentingViewController:(UIViewController *)presentingViewController {
if (self = [super initWithPresentedViewController:presentedViewController presentingViewController:presentingViewController]) {
self.dimmingView = [[UIView alloc]init];
self.dimmingView.backgroundColor = [UIColor blackColor];
}
return self;
}
-(void)presentationTransitionWillBegin {
self.presentedViewController.view.clipsToBounds = YES;
self.presentedViewController.view.layer.cornerRadius = 10.0f;
self.dimmingView.frame = self.containerView.bounds;
self.dimmingView.alpha = 0.0f;
[self.containerView insertSubview:self.dimmingView atIndex:0];
[[self.presentedViewController transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
/* Reorganize views, or move child view controllers */
self.dimmingView.alpha = 0.7f;
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}];
}
-(void)dismissalTransitionWillBegin {
[[self.presentedViewController transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
/* Reorganize views, or move child view controllers */
self.dimmingView.alpha = 0.0f;
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.dimmingView removeFromSuperview];
}];
}
-(CGRect)frameOfPresentedViewInContainerView {
return CGRectInset(self.containerView.frame, 30, 100);
}
@end