Skip to content

Instantly share code, notes, and snippets.

@D-32
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save D-32/c141c4a04ce72cc74237 to your computer and use it in GitHub Desktop.

Select an option

Save D-32/c141c4a04ce72cc74237 to your computer and use it in GitHub Desktop.

Revisions

  1. D-32 revised this gist Aug 6, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ModalViewController
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,7 @@ static CGFloat kHeight = 480;
    _container = [[UIView alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height / 2, self.view.frame.size.width - 40, 0)];
    _container.backgroundColor = [UIColor whiteColor];
    _container.layer.cornerRadius = 6;
    _container.clipsToBounds = YES;
    [self.view addSubview:_container];
    }

  2. D-32 revised this gist Aug 6, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions ModalViewController
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    static CGFloat kHeight = 480;

    @implementation ModalViewController {
    UIView *_bg;
    UIView *_container;
    @@ -32,8 +34,8 @@
    [UIView animateWithDuration:0.3 animations:^{
    _bg.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
    CGRect f = _container.frame;
    f.origin.y = self.view.frame.size.height / 2 - 240;
    f.size.height = 480;
    f.origin.y = self.view.frame.size.height / 2 - kHeight / 2;
    f.size.height = kHeight;
    _container.frame = f;
    }];
    }
  3. D-32 created this gist May 13, 2015.
    50 changes: 50 additions & 0 deletions ModalViewController
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    @implementation ModalViewController {
    UIView *_bg;
    UIView *_container;
    }

    - (instancetype)init {
    if (self = [super init]) {
    self.providesPresentationContextTransitionStyle = YES;
    self.definesPresentationContext = YES;
    self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    }
    return self;
    }

    - (void)viewDidLoad {
    [super viewDidLoad];

    _bg = [[UIView alloc] initWithFrame:self.view.bounds];
    _bg.backgroundColor = [UIColor clearColor];
    [_bg addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)]];
    [self.view addSubview:_bg];

    _container = [[UIView alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height / 2, self.view.frame.size.width - 40, 0)];
    _container.backgroundColor = [UIColor whiteColor];
    _container.layer.cornerRadius = 6;
    [self.view addSubview:_container];
    }

    - (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [UIView animateWithDuration:0.3 animations:^{
    _bg.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
    CGRect f = _container.frame;
    f.origin.y = self.view.frame.size.height / 2 - 240;
    f.size.height = 480;
    _container.frame = f;
    }];
    }

    - (void)close {
    [UIView animateWithDuration:0.3 animations:^{
    _bg.backgroundColor = [UIColor clearColor];
    CGRect f = _container.frame;
    f.origin.y = self.view.frame.size.height;
    _container.frame = f;
    } completion:^(BOOL finished) {
    [self dismissViewControllerAnimated:NO completion:nil];
    }];
    }