'UIPopoverController'已过时:自iOS 9.0起首次过时。

6

我开发了一个项目,出现了错误:

'UIPopoverController'已被弃用:自iOS 9.0起首次被弃用-UIPopoverController已被弃用。现在将弹出窗口实现为UIViewController演示文稿。使用UIModalPresentationPopover和UIPopoverPresentationController的模态演示样式。

我的代码如下:

ViewController.h:

#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
#import <MobileCoreServices/MobileCoreServices.h>



@interface ViewController : UIViewController
 <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

- (IBAction)touch:(id)sender;

@end

@interface SecondView : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>



//video gallery
@property (strong,nonatomic) UIPopoverPresentationController *popOver;
@property (weak, nonatomic) IBOutlet UIView *studentView;
@property (strong, nonatomic) NSURL *videoURL;


@end

ViewController.m:

- (void)openGallery {

UIImagePickerController *Picker=[[UIImagePickerController alloc] init];
Picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
Picker.mediaTypes=[[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,  nil];
Picker.delegate=self;

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

{


    UIPopoverController *popController=[[UIPopoverController alloc] initWithContentViewController:Picker];
    [popController presentPopoverFromRect:CGRectMake(0, 600, 160, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popOver=popController;
}
else
{
    [self presentViewController:Picker animated:YES completion:nil];
}
}


#pragma mark - UIImagePickerControllerDelegate

 - (void)imagePickerController:(UIImagePickerController *)picker    didFinishPickingMediaWithInfo:(NSDictionary *)info {


if (self.studentView) {

    self.videoURL = info[UIImagePickerControllerMediaURL];
    [picker dismissViewControllerAnimated:YES completion:NULL];


    [[NSUserDefaults standardUserDefaults] setObject:[self.videoURL absoluteString] forKey:@"url1"];
}

}

我无法为UiModalPresentationPopover找到适当的参考文献。有人能帮我解决这个错误吗?非常感谢任何帮助。谢谢。

1个回答

5

使用 UIModalPresentationPopover

在水平正常的环境下,采用弹出视图的方式显示内容。背景内容会变暗,点击弹窗外部区域可关闭弹窗。如果不想让点击事件关闭弹窗,可以将一个或多个视图分配给相关的UIPopoverPresentationController对象的passthroughViews属性,该对象可以从popoverPresentationController属性中获取。

在水平紧凑的环境下,此选项与UIModalPresentationFullScreen相同。

iOS 8.0及更高版本可用。

参考资料:UIModalPresentationStyle参考文档

例如:

ModalViewController *modal = [[ModalViewController alloc] init];
modal.modalPresentationStyle = UIModalPresentationPopover;
modal.transitioningDelegate = self;
modal.popoverPresentationController.sourceView = self.view;
modal.popoverPresentationController.sourceRect = CGRectZero;
modal.popoverPresentationController.delegate = self;

[self presentViewController:modal animated:YES completion:nil];

否则使用UIPopoverPresentationController

例如

UIPopoverPresentationController *popController = [self. popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionAny;
popController.barButtonItem = self.leftButton;
popController.delegate = self;

附加 参考


上述代码在单击弹出窗口内可用的标签时无法导航到屏幕。 [popover presentPopoverFromRect:self.titleView.frame inView:self.navigationController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; - sejn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接