0
votes

For a synch screen I made a ModalViewController on ios5. I used this code:

    synchViewController = [[SynchViewController alloc] initWithNibName:@"SynchViewController" bundle:nil];
    synchViewController.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:synchViewController animated:YES];

    synchViewController.view.superview.frame = CGRectMake(0,0,SYNCHVIEW_WIDTH,SYNCHVIEW_HEIGHT);

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    CGPoint center = CGPointMake(CGRectGetMidX(screenBounds), CGRectGetMidY(screenBounds));
    synchViewController.view.superview.center = CGPointMake(center.y, center.x);

The controller was designed in the xib file. This code worked.

Now under ios6 the presentModalViewController is depreciated. I changed the method, but now the modal view controller is totally displaced and got a wrong size.

How can I just have something like the iMessage login screen with the size of my designed xib layout?

EDIT: It works with this code: synchViewController = [[SynchViewController alloc] initWithNibName:@"SynchViewController" bundle:nil];

    synchViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    synchViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:synchViewController animated:YES completion:nil];
    synchViewController.view.superview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    synchViewController.view.superview.frame = CGRectMake(0,0,
                                                     SYNCHVIEW_WIDTH,// Width
                                                     SYNCHVIEW_HEIGHT// Height
                                                     );


    synchViewController.view.superview.bounds = CGRectMake(0, 0, SYNCHVIEW_WIDTH, SYNCHVIEW_HEIGHT);
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    CGPoint center = CGPointMake(CGRectGetMidX(screenBounds), CGRectGetMidY(screenBounds));
    synchViewController.view.superview.center = CGPointMake(center.y, center.x);

But only if I set animated to YES. When im trying to load it without an animation, its totally displaced again, why?

1

1 Answers

1
votes

What are you trying to achieve by the following code?

synchViewController.view.superview.frame = CGRectMake(0,0,SYNCHVIEW_WIDTH,SYNCHVIEW_HEIGHT);
...
synchViewController.view.superview.center = CGPointMake(center.y, center.x);

The size and position of a modal (presented) controller is defined by modalPresentationStyle and trying to change it will never work reliably.

If you want a different size of a presented controller, you have to write the controller by yourself (as a child view controller), insert it into the view hierarchy and block user interaction on the presenting controller.

However, I strongly advise to just use a native modal controller with the default size.