首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iPhone应用中创建弹出窗口?

如何在iPhone应用中创建弹出窗口?
EN

Stack Overflow用户
提问于 2012-07-19 02:28:01
回答 2查看 27.5K关注 0票数 15

我正在寻找iPhone中的弹出窗口,我想让它像iOS 5阅读器功能:

经过很少的研究,我找到了WEPopover和FPPopover,但我正在寻找是否有像这个内置的iphone SDK这样的API。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-19 02:38:28

你可以用一些自定义的图片制作一个UIView,并在视图顶部显示一个动画,作为一个"popover“,带有如下按钮:

代码语言:javascript
复制
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>

票数 26
EN

Stack Overflow用户

发布于 2015-05-24 06:01:54

由于我们现在可以在iOS8上创建弹出窗口,这在iPhone上和在iPad上是一样的,对于那些开发通用应用程序的人来说,这将是特别棒的,因此不需要单独创建视图或代码。

您可以在此处获得类和演示项目:https://github.com/soberman/ARSPopover

您所需要做的就是将UIViewController子类,符合UIPopoverPresentationControllerDelegate协议,并设置所需的modalPresentationStyledelegate值:

代码语言:javascript
复制
// 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.
}

然后,用要显示它的方法实例化新创建的子类,并将另外两个值分配给sourceViewsourceRect。它看起来是这样的:

代码语言:javascript
复制
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。

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11547969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档