弹出窗口在 iPhone 4 秒后未正确显示

Popup is not showing up properly in iPhone 4s

使用下面的代码后,弹出窗口在某些设备中无法正常显示,例如 iPhone 4s、iPad 等....它在 iPhone 6.[=14= 中正常工作]

下面是代码,

UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Set Bookmark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
    Definition *toBookmark = [appDelegate.encyclopedia getByIdxTerm:mydef.idxterm];

    BOOL bBook = [[appDelegate prefsdb] addBookmark:[[appDelegate encyclopedia] objectInListAtIndex:toBookmark.encIdx]];

    [alert1 dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
    [alert1 dismissViewControllerAnimated:YES completion:nil];
}];

[alert1 addAction:ok];
[alert1 addAction:cancel];
[self presentViewController:alert1 animated:YES completion:nil];

在我使用在 iOS 8 中弃用的 UIActionsheet 之前....我正在使用 iOS 8.

截图来自iPhone 4s

截图来自 iPhone 5

它应该像 iphone5 一样......请帮忙

添加高度限制可能会解决问题:

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:alert1.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:self.view.frame.size.height];
[alert1.view addConstraint:constraint];

替代解决方案:如果您不介意布局设计,请将 preferredStyle:UIAlertControllerStyleActionSheet 更改为 preferredStyle:UIAlertControllerStyleAlert。