如何在iPhone应用程序中创buildpopover?

我正在寻找iPhone中的popover,我想让它像iOS 5 Readerfunction:

在这里输入图像说明

经过一番研究,我发现WEPopover和FPPopover,但我看看是否有像这个API内置iPhone SDK的东西。

你可以用一些自定义的艺术品制作一个UIView ,并在你的视图之上用一些animation将其显示为一个“popover”,如下所示:

 UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 100, 50)]; //<- change to where you want it to show. //Set the customView properties customView.alpha = 0.0; customView.layer.cornerRadius = 5; customView.layer.borderWidth = 1.5f; customView.layer.masksToBounds = YES; //Add the customView to the current view [self.view addSubview:customView]; //Display the customView with animation [UIView animateWithDuration:0.4 animations:^{ [customView setAlpha:1.0]; } completion:^(BOOL finished) {}]; 

如果你想使用customView.layer ,不要忘记#import <QuartzCore/QuartzCore.h>

自iOS8以来,我们现在可以创buildpopup窗口,这与iPad上的一样,对于那些制作通用应用程序的用户来说,这将是特别棒的,因此无需制作单独的视图或代码。

你可以在这里获得这个类以及演示项目: https : //github.com/soberman/ARSPopover

所有你需要做的是UIViewController子类,符合UIPopoverPresentationControllerDelegate协议,并设置所需的modalPresentationStyle以及delegate值:

 // This is your CustomPopoverController.m @interface CustomPopoverController () <UIPopoverPresentationControllerDelegate> @end @implementation CustomPopoverController.m - (instancetype)init { if (self = [super init]) { self.modalPresentationStyle = UIModalPresentationPopover; self.popoverPresentationController.delegate = self; } return self; } - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { return UIModalPresentationNone; //You have to specify this particular value in order to make it work on iPhone. } 

之后,在要显示它的方法中实例化新创build的子类,并为sourceViewsourceRect分配两个更多的值。 它看起来像这样:

 CustomPopoverController *popoverController = [[CustomPopoverController alloc] init]; popoverController.popoverPresentationController.sourceView = sourceView; //The view containing the anchor rectangle for the popover. popoverController.popoverPresentationController.sourceRect = CGRectMake(384, 40, 0, 0); //The rectangle in the specified view in which to anchor the popover. [self presentViewController:popoverController animated:YES completion:nil]; 

而且你有它,很好,整齐模糊的popover。