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

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

问题描述

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

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:

具体来说,iPhone的截图在右边,在哪里,如果用户点击主窗口中的脸部或UIView,会出现部分透明的弹出窗口,其中包含更详细的信息 - 例如肖像照片和文本数据 - 但原始视图(此处的照片集合)仍然可见,并且计时器/ counter在该视图中继续滴答。

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.

我认为这是一个可能的解决方案 iPhone模态视图比屏幕更小但它对我不起作用。上面没有显示的是取消按钮,我也计划放入popover,以便用户可以返回到下面的视图。当计时器到期时,详细视图也会消失。

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.

我应该使用presentModalViewController和演示者/演示方案,还是使用与故事板segue的父子视图关系,或者我应该使用loadNibNamed,还是某种黑客来克服iPhone显示非全屏模态视图的限制?它将覆盖屏幕的大部分,但我想确保下面的视图是可见的并且仍然是活动的,因为它向不在popover中的用户提供信息(计时器等)。用户不需要与下面的屏幕进行交互,但我希望它部分可见。

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.

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

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.

警告:我的术语可能不正确且不准确。弹出窗口或弹出窗口可以是UIView,UIViewController,UIWindow,或者以编程方式解决问题的最佳方法。我并不认为它是一种特定的小部件类型,只要功能反映了我正在寻找的东西。

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.

提前感谢您的建议!

推荐答案

你想实现这个目标吗?

以下是两个不同的 viewControllers 一个高于另一个。 vc2 是一个 childViewController vc1 透明背景。在你的情况下你可以用 backgroundColor black UILabel 堆栈顶部c $ c>和 alpha = 0.5

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.

所有 vc2 将在 vc2.m 上触发。在图像上单击使用此代码:

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

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

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

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

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

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

编辑

所以做一件事,首先将 UIView 添加到 xib 这将是一个圆形边框,框架将根据您的屏幕截图显示。

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.

对于圆形边框,您可以使用此。此 UIView backgroundColor 将是 clearColor

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

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

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.

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

Then start putting your other controls inside UIView

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

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