set size of iPhone view controller

2019-09-09 19:26发布

I am segueing to a view controller called SmallerVC. I want to set the size of SmallerVC to 300 X 300. So far I am not having much luck. I have tried the answers at the following link separately and then together, they don't work: ios5 - size of modal view controller with storyboard. I am using Xcode-5 and iOS-7. Has anyone successfully done this? I came to iOS with the prejudice that anything I can do on Android I should be able to do more easily on iOS. And so far iOS has been constantly disabusing me of that notion. Can such a simple thing be really so difficult?

To get to the button of things, I set my content view's color to clearColor. And sure enough, during transition it is clear, but upon transitioning a black background shows up that covers the whole screen. So my guess is I need to access and manipulate some sort of parent. Any ideas how I might do this?

UPDATE: my code

Here is the latest iteration of my code. The modal segue is set in storyboard.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"smaller_view_id"]) {
        if ([segue.destinationViewController isKindOfClass:[SmallerVC class]]) {
            UIViewController *container = (SmallerVC *)segue.destinationViewController;
            container.modalPresentationStyle = UIModalPresentationFormSheet;

            id sourceController = segue.sourceViewController;
            UIView *destinationView = [container view];
            CGFloat x, y, w, h;
            x = 10;//destinationView.superview.frame.origin.x;
            y = 50;//destinationView.superview.frame.origin.y;
            w = 300;  // Your desired modal view width
            h = 300;  // Your desired modal view height
            destinationView.superview.frame = CGRectMake(x, y, w, h);
            destinationView.frame = CGRectMake(x, y, w, h);
            destinationView.superview.center = [[sourceController view] center];
            [container setModalPresentationStyle:UIModalPresentationFormSheet];
            [container setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
           // [sourceController presentViewController:container animated:YES completion:nil];
            NSLog(@"SEGUE CALL IS SEEN");
#pragma warning - pass in previous review data
        }
    }
}

0条回答
登录 后发表回答