set size of iPhone view controller

我是研究僧i 提交于 2020-01-07 02:22:21

问题


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
        }
    }
}

来源:https://stackoverflow.com/questions/25250510/set-size-of-iphone-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!