Xcode: How To Create A PopUp View Controller That Appears In Another View Controller

后端 未结 7 582
-上瘾入骨i
-上瘾入骨i 2021-01-31 12:27

Basically what I am trying to figure out to do is, say I have one View Controller, called V1, that has a regular view inside it and a button. Now, when you tap that button, I wa

7条回答
  •  天涯浪人
    2021-01-31 12:43

    If you want to present this as a modal popup in iOS 8 with a similar style to the OP's screenshot here's what I did:

    UIViewController *V2 = [[UIViewController alloc] init];  // V2 is the popup
    V2.modalPresentationStyle = UIModalPresentationFormSheet;
    V2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    V2.preferredContentSize = CGSizeMake(325, 75); // size of popup view
    [V1 presentModalViewController:V2 animated:YES]; // V1 is the current topmost view controller
    

    I like this better than using a UIPopover because you don't need to mess with arrow directions and the user cannot close it by tapping outside of the popup.

    These properties can also be set in a storyboard/nib via the designer. To set preferredContentSize check "Use Preferred Explicit Size" and set the values.

    This only works on the iPad.

提交回复
热议问题