【问题标题】:Why are the dimensions of my modal view different from what I expect?为什么我的模态视图的尺寸与我预期的不同?
【发布时间】:2013-09-14 16:38:02
【问题描述】:

我在 IB 中创建了这个对话框:

我通过以下方式设置 segue:

这就是我配置 ViewController 的方式:

这就是我配置视图指标的方式:

这是我在 iOS 模拟器中得到的:

那么:有人能告诉我为什么吗,我怎么能按照我的视觉意图来获得它,以及我在哪里可以找到一个非常好的界面构建器教程?

提前致谢。

【问题讨论】:

  • 你如何分配/显示这个模态?

标签: ios interface-builder modal-dialog viewcontroller popover


【解决方案1】:

“表单”模式演示样式始终使用相同大小的容器,并且您不能覆盖它。在 iOS 7 或更高版本中,您可以定义自定义模式演示样式来完成您想要的,或搜索 GitHub。

这是一个与 iOS 6 兼容的具有自定义大小的实现。

/** Created in answer to mirx's question at http://stackoverflow.com/questions/18803961/why-are-the-dimensions-of-my-modal-view-different-from-what-i-expect/18805374?noredirect=1#comment27741546_18805374 */

@interface AHPresentingViewController : UIViewController
@property (nonatomic, weak) UIView *presentedBackgroundView;
@property (nonatomic, weak) UIViewController *formController;
@end

@implementation AHPresentingViewController

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    UITableViewController *table = [UITableViewController new];
    table.title = @"Form";
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:table];
    table.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissPresentedForm:)];
    [self presentForm:nav size:CGSizeMake(320, 240)];
}
-(void)presentForm:(UIViewController *)formVC size:(CGSize)size {
    if(self.formController) return;
    NSLog(@"Form view: %@",formVC.view);
    UIView *background;
    self.presentedBackgroundView = background = [[UIView alloc] initWithFrame:self.view.bounds];
    background.opaque = NO;
    background.backgroundColor = [UIColor blackColor];
    background.alpha = 0;
    [self.view addSubview:background];
    formVC.view.frame = (CGRect){CGPointZero, size};
    formVC.view.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2., CGRectGetHeight(self.view.bounds) + CGRectGetHeight(formVC.view.bounds));
    [self addChildViewController:formVC];
    self.formController = formVC;
    [self.view addSubview:formVC.view];

    [UIView animateWithDuration:0.5 animations:^{
        background.alpha = 0.4;
        formVC.view.center = CGPointMake(self.view.bounds.size.width / 2., self.view.bounds.size.height / 2.);
    }];
}
-(void)dismissPresentedForm:(id)sender {
    if(!self.formController) return;
    [UIView animateWithDuration:0.5 animations:^{
        self.presentedBackgroundView.alpha = 0;
        self.formController.view.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2., CGRectGetHeight(self.view.bounds) + CGRectGetHeight(self.formController.view.bounds));
    } completion:^(BOOL finished) {
        [self.presentedBackgroundView removeFromSuperview];
        [self.formController.view removeFromSuperview];
        [self.formController removeFromParentViewController];
    }];
}
@end

【讨论】:

  • 谢谢,我现在可以做什么(使用 iOS6)来获得我想要的输入对话框?
  • 编辑答案以包含示例解决方案
猜你喜欢
  • 2023-02-02
  • 2019-08-31
  • 2019-12-22
  • 1970-01-01
  • 2016-11-17
  • 2016-09-04
  • 2016-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多