Set Frame iOS8 in ModalViewController with UIModalPresentationCustom

1.4k views Asked by At

I want to present a modal view controller. In iOS7 everything runs fine but in iOS8 the frame of view controller is changed. I read some answers and one of the solutions is to set the preferredContentSize and the modalPresentationStyle = UIModalPresentationFormSheet.

But i need my modalPresentationStyle = UIModalPresentationCustom and i can't set the frame of view controller with this presentation style.

My code is:

- (void)presentViewController:(UIViewController*)viewController withCustomSize:(NSValue*) size withInitialSetup:(void (^)(void))setupBlock withCompletion:(void (^)(void))completion {

    UiViewController * navCon = [[UIViewController alloc] initWithRootViewController:viewController];
    navCon.shouldDismissKeyboardOnResign = YES;

    if (SYSTEM_VERSION_LESS_THAN(IOS8)){

        navCon.modalPresentationStyle   = UIModalPresentationFormSheet;
        navCon.modalTransitionStyle     = UIModalTransitionStyleCoverVertical;


    } else {

        navCon.modalPresentationStyle   = UIModalPresentationCustom;
        navCon.modalTransitionStyle     = UIModalTransitionStyleCrossDissolve;

    }

    [viewController setupCustomNavigationBar];

    setupBlock();

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(IOS8)) {

        navCon.transitioningDelegate = self;

        if (size) {

            CGSize sz = size.CGSizeValue;
            navCon.preferredContentSize = CGSizeMake(sz.width, sz.height);

        }else {

            navCon.preferredContentSize = CGSizeMake(kPopupsWidth, kPopupsHeight);
        }
    }

    [self presentViewController:navCon animated:YES completion:completion];

    if (SYSTEM_VERSION_LESS_THAN(IOS8)) {

        if (size) {

            CGSize sz = size.CGSizeValue;
            navCon.view.superview.bounds = CGRectMake(0, 0, sz.width, sz.height);

        } else {

            navCon.view.superview.bounds = CGRectMake(0, 0, kPopupsWidth, kPopupsHeight);
        }

        [navCon.view.superview.layer setCornerRadius: 8];
        [navCon.view.superview.layer setBorderColor: [UIColor clearColor].CGColor];
        [navCon.view.superview.layer setBorderWidth: 2];
        [navCon.view.superview setClipsToBounds: YES];   
    }
}

I set the preferedContentSize but the frame doesn't change. Any idea why this happens?

1

There are 1 answers

1
InkGolem On BEST ANSWER

If you're going to use UIModalPrestationCustom you have to provide a UIViewControllerTransitioningDelegate, otherwise its going to use the default transitioning delegate, which in your case sounds like a form sheet delegate.