我正在为iPad开发一款应用。在一个功能中,我想显示 FullCustom Popover 。
为此我的代码如下: -
DuplicateViewController *viewControllerForPopover =
[self.storyboard instantiateViewControllerWithIdentifier:@"DuplicatePopoverVC"];
viewControllerForPopover.arr_studentDetail = self.arrStudentDetail;
viewControllerForPopover.dictSelectedProg = dictSelectedProgram;
self.popover = [[UIPopoverController alloc]
initWithContentViewController:viewControllerForPopover];
[self.popover setPopoverContentSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
viewControllerForPopover.modalPresentationStyle = UIModalPresentationFullScreen;
[self.popover setBackgroundColor:[[UIColor darkGrayColor] colorWithAlphaComponent:0.4]];
[self.popover presentPopoverFromRect:self.view.bounds inView:self.view permittedArrowDirections:0 animated:YES];
我设置了popover大小并尝试了其他选项,但无法全屏显示。
ViewDidLoad - > DuplicateViewController
[view_main.layer setBorderWidth:5.0f];
[view_main.layer setCornerRadius:25.0f];
[view_main.layer setBorderColor:[UIColor colorWithRed:(29.0f/255.0f) green:134.0f/255.0f blue:140.0f/255.0f alpha:1.0f].CGColor];
但是在运行App时,它显示如下: -
请帮我显示全屏Popover。非常感谢你。
答案 0 :(得分:1)
创建两个类 第一个应该继承UIPopoverController 第二个应该继承UIPopoverBackgroundView
例如:
<强> CustomUIPopoverController.h 强>
@interface CustomUIPopoverController : UIPopoverController
<强> CustomUIPopoverController.m 强>
@implementation CustomUIPopoverController
- (id)initWithContentViewController:(UIViewController *)viewController {
self = [super initWithContentViewController:viewController];
if (self) {
self.popoverBackgroundViewClass = [CustomUIClearPopoverBackgroundView class];
[self setPopoverContentSize:viewController.view.frame.size];
}
return self;
}
@end
<强> CustomUIClearPopoverBackgroundView.h 强>
@interface CustomUIClearPopoverBackgroundView : UIPopoverBackgroundView
<强> CustomUIClearPopoverBackgroundView.m 强>
#import "CustomUIClearPopoverBackgroundView.h"
@implementation CustomUIClearPopoverBackgroundView
#pragma mark - no arrow
+ (CGFloat)arrowHeight {
return 0;
}
+ (CGFloat)arrowBase {
return 0;
}
- (CGFloat)arrowOffset {
return 0;
}
- (void)setArrowOffset:(CGFloat)arrowOffset {
}
- (UIPopoverArrowDirection)arrowDirection {
return 0;
}
- (void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
}
#pragma mark - no margins
+ (UIEdgeInsets)contentViewInsets {
return UIEdgeInsetsZero;
}
#pragma mark - fully transparent (default is 0.15)
+(BOOL)wantsDefaultContentAppearance {
return NO;
}
- (void)willMoveToWindow:(UIWindow *)newWindow {
[super willMoveToWindow:newWindow];
// hide shadow image view
[self.superview.subviews[0] setHidden:YES];
}
@end
我用过这个,但我不太喜欢它。 第二个选项是创建容器视图并隐藏/显示它。 这样它就是一个纯粹的视图控制器,你不需要搞乱弹出的东西 要创建透明度,使容器视图background = clear,视图控制器视图背景颜色=清除,并为视图控制器的大小添加半透明黑色背景的半透明按钮。单击按钮关闭窗口(=与弹出背景相同的效果)