iOS,PopOverPresentationController 问题,.xib
<p><p>我有一个 NavigationController,另一个 Controller 被压入它的堆栈:BNRDetailsViewController。现在,在 BNRDetailsViewController 中,我试图在按下工具栏按钮时显示一个弹出窗口,这将向我展示 UIImagePickerController(仅在 iPad 设备上)。因此,我尝试遵循以下 stackoverflow 线程:</p>
<p> <a href="https://stackoverflow.com/questions/25319179/uipopoverpresentationcontroller-on-ios-8-iphone" rel="noreferrer noopener nofollow">UIPopoverPresentationController on iOS 8 iPhone</a> </p>
<p>但没有成功。如果我只使用他们的代码,我会收到一条错误消息,提示 <code>push navigationController is not supported</code>。如果我尝试像这样推送新创建的 <code>UIPopoverPresentationController</code>: <code>;</code> 它会崩溃,因为 <code>UIPopoverPresentationController</code> 不是 <code>UIViewController</code> 类型,所以,我想,我不能只是将它压入堆栈。 </p>
<p>在这种特殊情况下,您建议怎么做? </p>
<p>这是我现在拥有的在按下工具栏按钮时触发的代码:</p>
<pre><code>- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [ init];
// If the device have camera, take a picture, otherwise,
// just pick from photo library
if () {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
// Place image picker on the screen
//;
// Place image picker on the screen
// Check for iPad device before instantiating the popover controller
if (.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Create a new popover controller that will display the imagePicker
_imagePickerPopover = [ initWithPresentedViewController:imagePicker presentingViewController:self];
imagePicker.preferredContentSize = CGSizeMake(280, 200);
_imagePickerPopover.delegate = self;
_imagePickerPopover.sourceView = self.view;
CGRect frame = [ frame];
frame.origin.y = frame.origin.y + 20;
_imagePickerPopover.sourceRect = frame;
// ;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是基于您的代码的代码,它将使弹出框显示在 iPad 上。</p>
<pre><code>if (.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
imagePicker.modalPresentationStyle = UIModalPresentationPopover;
imagePicker.preferredContentSize = CGSizeMake(280, 200);
CGRect frame = [ frame];
frame.origin.y = frame.origin.y + 20;
UIPopoverPresentationController *popoverController =
imagePicker.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = frame;
[self.navigationController presentViewController:imagePicker
animated:YES completion:nil];
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS,PopOverPresentationController 问题,.xib,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33713482/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33713482/
</a>
</p>
页:
[1]