在 iPhone 上显示弹出透明窗口的最佳方法? [英] Best Method to Show a Popup Transparent Window on iPhone?

查看:54
本文介绍了在 iPhone 上显示弹出透明窗口的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Xcode 4.6 中构建一个 iOS 6 iPhone 应用程序并且想知道实现以下类型的弹出窗口的最佳方法:

具体来说,右侧的 iPhone 屏幕截图,如果用户在主窗口中点击人脸或 UIView,则会出现一个部分透明的弹出窗口,其中包含更详细的信息——例如肖像照片和文本数据——但是原始视图(此处为照片集)仍然可见,并且计时器/计数器在该视图中继续滴答作响.

我认为这将是一个可能的解决方案 iPhone Modal View 比屏幕小 但它对我不起作用.上面没有显示的是一个取消按钮,我也打算把它放在弹出窗口中,以便用户可以返回到下面的视图.当计时器到期时,详细视图也消失了.

我应该使用presentModalViewController 和presenter/presented 方案,还是使用带有storyboard segue 的父子视图关系,或者我应该使用loadNibNamed,或者某种hack 来克服iPhone 显示非完整的限制-屏幕模态视图?它会覆盖大部分屏幕,但我想确保下面的视图可见并且仍然处于活动状态,因为它向用户提供不在弹出窗口中的信息(计时器等).用户不需要与下面的屏幕交互,但我希望它部分可见.

我在主故事板中将弹出视图设计为单独的视图控制器,而不是作为 xib 文件.连接和出口是从接口构建器到我的代码形成的,称为 ProfileViewController.

警告:我的术语可能不正确和不准确.popup 或 popover 可以是 UIView、UIViewController、UIWindow 或任何以编程方式解决问题的最佳方法.只要功能反映了我的需求,我就不会将其绑定为某种小部件类型.

预先感谢您的建议!

解决方案

你想达到这个目标吗?

这里有两个不同的 viewController 一个在另一个之上.vc2vc1childViewController ,具有 transparent 背景.在您的情况下,您可以将 UILabelbackgroundColor blackalpha = 0.5 放在堆栈顶部.

vc2 的所有事件都将在 vc2.m 上触发.在图片点击上使用此代码:

- (IBAction)imageClick{vc2 *viewController = [[vc2 alloc]init];[self addChildViewController:viewController];viewController.view.frame = self.view.frame;[self.view addSubview:viewController.view];viewController.view.alpha = 0;[viewController didMoveToParentViewController:self];[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{viewController.view.alpha = 1;}完成:无];}

vc2.m 中把它放在 viewDidLoad 上,使这个 viewController透明.

self.view.backgroundColor = [UIColor clearColor];self.view.opaque = 是;

使透明视图成为 viewController 将使您的代码干净,因为 vc2 的所有代码都在一个单独的类中.

编辑

所以做一件事,首先将 UIView 添加到您的 xib 中,这将是一个圆角边框,并且框架将是您想要的屏幕截图.

对于圆形边框,您可以使用此category.这个 UIViewbackgroundColor 将是 clearColor:

- (void)setRoundedBorder:(float) radius borderWidth:(float)borderWidth color:(UIColor*)color{CALayer * l = [自层];[l setMasksToBounds:YES];[l setCornerRadius:radius];//你甚至可以添加边框[l setBorderWidth:borderWidth];[l setBorderColor:[颜色CGColor]];}

现在放一个UILabel/UIView/UIImage,它的frame等于上面的UIView,alpha为0.5,背景颜色为黑色.您可以直接从 xib 执行此操作.无需通过代码设置frame.

然后开始将其他控件放入 UIView

I'm building an iOS 6 iPhone app in Xcode 4.6 and am wondering about the best way to achieve the following type of popup window:

Specifically, the iPhone screenshot on the right, where, if a user taps on a face or UIView in the main window, a partially transparent popover appears with more detailed information -- such as a portrait photo and textual data -- but the original view (a photo collection here) remains visible, and the timers/counters continue ticking down in that view.

I thought this would be a possible solution iPhone Modal View Smaller that the screen but it doesn't work for me. Not shown above is a cancel button that I am also planning to put in the popover, so that the user can return to the view underneath. When the timer expires, the detailed view also disappears.

Should I use presentModalViewController and the presenter/presented scheme, or use a parent-child-view relationship with a storyboard segue, or should I use loadNibNamed, or some kind of hack to overcome the iPhone's limitation of displaying a non-full-screen modal view? It'll cover most of the screen but I want to make sure the view underneath is visible and still active, since it provides information to the user that isn't in the popover (timer, etc.). The user won't need to interact with the screen below, but I'd like it to be partially visible.

I designed the popup view as a separate viewcontroller in my main storyboard, not as a xib file. The connections and outlets are formed from interface builder to my code, called ProfileViewController.

WARNING: My terminology may be incorrect and inaccurate. The popup or popover can be a UIView, UIViewController, UIWindow, or whatever works best programatically to solve the problem. I'm not tied to it being a certain widget type, as long as the functionality mirrors what I'm seeking.

Thanks in advance for your suggestions!

解决方案

do you want to achieve this?

Here are two different viewControllers one above other one. vc2 is a childViewController of vc1 with a transparent background. In your case you can put a UILabel top of the stack with backgroundColor black and alpha = 0.5.

All events of vc2 will fire on vc2.m. Use this code on image click:

- (IBAction)imageClick 
{
    vc2 *viewController = [[vc2 alloc]init];
    [self addChildViewController:viewController];
    viewController.view.frame = self.view.frame;
    [self.view addSubview:viewController.view];
    viewController.view.alpha = 0;
    [viewController didMoveToParentViewController:self];

    [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^
     {
         viewController.view.alpha = 1;
     }
                     completion:nil];
}

And in vc2.m put this on viewDidLoad to make this viewControllertransparent.

self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = YES;

Making transparent view a viewController will make your code clean as all code of vc2 will be in a separate class.

EDIT

So do one thing, First add a UIView to your xib which will be a rounded border and frame will be that you want as per your screenshot.

For rounded border, you can use this category. backgroundColor of this UIView will be clearColor:

- (void)setRoundedBorder:(float) radius borderWidth:(float)borderWidth color:(UIColor*)color
{
    CALayer * l = [self layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:radius];
    // You can even add a border
    [l setBorderWidth:borderWidth];
    [l setBorderColor:[color CGColor]];
}

Now put a UILabel/UIView/UIImage whose frame is equal to UIView above and alpha is 0.5 with black background color. You can do this directly from xib. No need to set frame through code.

Then start putting your other controls inside UIView

这篇关于在 iPhone 上显示弹出透明窗口的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆