【发布时间】:2014-01-15 15:47:29
【问题描述】:
我的一个视图控制器以UIModalPresentationFormSheet 的呈现方式加载另一个视图控制器:
- (void)loadNotesForm {
if ([helper isOrderReadyForSubmission:self.coreDataOrder]) {
CIFinalCustomerInfoViewController *ci = [[CIFinalCustomerInfoViewController alloc] init];
ci.order = self.coreDataOrder;
ci.modalPresentationStyle = UIModalPresentationFormSheet;
ci.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
ci.delegate = self;
[self presentViewController:ci animated:YES completion:nil];
}
}
在此模式 (CIFinalCustomerInfoViewController) 中,我以编程方式构造视图:
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[view setBackgroundColor:[UIColor blackColor]];
self.view = view;
CGFloat currentY = 8.0;
CGFloat verticalMargin = 8.0;
CGFloat horizontalMargin = 12.0;
UIFont *labelFont = [UIFont fontWithName:@"Futura-MediumItalic" size:27.0f];
UILabel *authorizedByLabel = [[UILabel alloc] initWithFrame:CGRectMake(62.0, currentY, 300.0, 35.0)];
authorizedByLabel.font = labelFont;
authorizedByLabel.textColor = [UIColor whiteColor];
authorizedByLabel.text = @"Authorized By";
[self.view addSubview:authorizedByLabel];
self.authorizedByTextField = [[UITextField alloc] initWithFrame:CGRectMake(62.0, CGRectGetMaxY(authorizedByLabel.frame)+ verticalMargin, 419.0, 44.0)];
self.authorizedByTextField.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.authorizedByTextField];
UILabel *notesLabel = [[UILabel alloc] initWithFrame:CGRectMake(62.0, CGRectGetMaxY(self.authorizedByTextField.frame) + verticalMargin, 300.0, 35.0)];
notesLabel.font = labelFont;
notesLabel.textColor = [UIColor whiteColor];
notesLabel.text = @"Notes";
[self.view addSubview:notesLabel];
self.notesTextView = [[UITextView alloc] initWithFrame:CGRectMake(62.0, CGRectGetMaxY(notesLabel.frame) + verticalMargin, 419.0, 100.0)];
[self.view addSubview:self.notesTextView];
UILabel *shipNotesLabel = [[UILabel alloc] initWithFrame:CGRectMake(62.0, CGRectGetMaxY(self.notesTextView.frame) + verticalMargin, 300.0, 35.0)];
shipNotesLabel.font = labelFont;
shipNotesLabel.textColor = [UIColor whiteColor];
shipNotesLabel.text = @"Ship Notes";
[self.view addSubview:shipNotesLabel];
self.shipNotesTextView = [[UITextView alloc] initWithFrame:CGRectMake(62.0, CGRectGetMaxY(shipNotesLabel.frame) + verticalMargin, 419.0, 80.0)];
[self.view addSubview:self.shipNotesTextView];
currentY = CGRectGetMaxY(self.shipNotesTextView.frame);
if (self.contactBeforeShippingConfig) {
UILabel *contactLabel = [[UILabel alloc] initWithFrame:CGRectMake(62.0, currentY, 300.0, 35.0)];
contactLabel.font = labelFont;
contactLabel.textColor = [UIColor whiteColor];
contactLabel.text = @"Contact Before Shipping?";
[self.view addSubview:contactLabel];
self.contactBeforeShippingCB.frame = CGRectMake(62 + CGRectGetMaxX(contactLabel.frame) + horizontalMargin, contactLabel.frame.origin.y, 150, 35);
[self.view addSubview:self.contactBeforeShippingCB];
currentY = CGRectGetMaxY(self.contactBeforeShippingCB.frame);
}
if(self.cancelConfig){
UILabel *cancelLabel = [[UILabel alloc] initWithFrame:CGRectMake(62.0, currentY, 300.0, 35.0)];
cancelLabel.font = labelFont;
cancelLabel.textColor = [UIColor whiteColor];
cancelLabel.text = @"Cancel if not shipped within following days?";
[self.view addSubview:cancelLabel];
self.cancelBeforeDaysPicker.frame = CGRectMake(62, CGRectGetMaxY(cancelLabel.frame), 400, 100);
[self.view addSubview:self.cancelBeforeDaysPicker];
currentY = CGRectGetMaxY(self.cancelBeforeDaysPicker.frame);
}
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchDown];
[cancelButton setBackgroundImage:[UIImage imageNamed:@"cart-cancelout.png"] forState:UIControlStateNormal];
[cancelButton setBackgroundImage:[UIImage imageNamed:@"cart-cancelin.png"] forState:UIControlStateHighlighted];
cancelButton.frame = CGRectMake(62.0, currentY+verticalMargin, 162.0, 56.0);
UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
[submitButton addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchDown];
[submitButton setBackgroundImage:[UIImage imageNamed:@"submitorderout.png"] forState:UIControlStateNormal];
[submitButton setBackgroundImage:[UIImage imageNamed:@"submitorderin.png"] forState:UIControlStateSelected];
submitButton.frame = CGRectMake(cancelButton.frame.origin.x + cancelButton.frame.size.width + horizontalMargin , cancelButton.frame.origin.y, 260.0, 56.0);
currentY = CGRectGetMaxY(submitButton.frame);
[self.view addSubview:cancelButton];
[self.view addSubview:submitButton];
}
我希望调整模态框的高度,以适应在 loadView 方法中添加的内容。如果我从加载视图中设置帧大小,那是行不通的。 SO上的其他帖子建议从显示它的控制器更改模态的大小并且有效。但是显示它的控制器不知道什么高度会覆盖由模态的loadView 方法加载的内容。
有没有办法使模态框的高度适合其在模态框内或其父级中的内容?
【问题讨论】:
-
啊!我的眼睛!一点空白不会有什么坏处。
-
抱歉,此代码正在进行中。
标签: ios