简体   繁体   English

iOS7和iOS8中的全屏自定义弹出窗口问题

[英]Full Screen Custom Popover issue in iOS7 and iOS8

I am developing an app for iPad only. 我仅在为iPad开发应用程序。 In which in for one functionality i want to display FullCustom Popover . 在其中一种功能中,我想显示FullCustom Popover

For that my code is as below:- 为此,我的代码如下:

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];

I set popover size and tried with other option but can't make it full screen. 我设置了弹出框大小,并尝试了其他选项,但无法使其全屏显示。

ViewDidLoad -> DuplicateViewController 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];

But while running App, It display as below:- 但是在运行App时,显示如下:-

在此处输入图片说明

Please help me to display full screen Popover. 请帮助我显示全屏Popover。 Thank you so much in advance. 提前非常感谢您。

create two classes the first one should inherit UIPopoverController the second one should inherit UIPopoverBackgroundView 创建两个类,第一个应该继承UIPopoverController,第二个应该继承UIPopoverBackgroundView

for example: 例如:

CustomUIPopoverController.h CustomUIPopoverController.h

@interface CustomUIPopoverController : UIPopoverController

CustomUIPopoverController.m 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 CustomUIClearPopoverBackgroundView.h

@interface CustomUIClearPopoverBackgroundView : UIPopoverBackgroundView

CustomUIClearPopoverBackgroundView.m 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

I used this but I don't like it very much. 我用了这个,但是我不太喜欢。 the second option is to create a container view and hide/show it as you like. 第二个选项是创建一个容器视图并根据需要隐藏/显示它。 this way it's a pure view controller and you don't need to mess with popup stuff to create the transparency, make your container view background = clear, the view controller view background color = clear, and add a semi-transparent button in the size of the view controller for the semi-transparent black background. 这样,它就是一个纯粹的视图控制器,您无需弄乱弹出窗口的东西即可创建透明度,使您的容器视图background = clear,视图控制器view background color = clear,并在大小中添加一个半透明按钮半透明的黑色背景的视图控制器的视图。 on click of the button close the window (= same effect as tapping the popup background) 单击按钮关闭窗口(=与点击弹出背景效果相同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM