4

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

弹出式屏幕截图

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

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

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

我在主情节提要中将弹出视图设计为单独的视图控制器,而不是作为 xib 文件。连接和出口是从界面生成器到我的代码形成的,称为 ProfileViewController。

警告:我的术语可能不正确和不准确。弹出窗口或弹出窗口可以是 UIView、UIViewController、UIWindow 或任何最适合以编程方式解决问题的方法。只要功能反映了我正在寻找的东西,我就不会将其绑定为某种小部件类型。

提前感谢您的建议!

4

4 回答 4

16

你想实现这个吗?

在此处输入图像描述

这里有两种不同viewControllers的一种。vc2是一个有childViewController背景的。在您的情况下,您可以使用and放置堆栈顶部。vc1transparentUILabelbackgroundColor 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;
     }
                     completion:nil];
}

vc2.m把它放在上面viewDidLoad以使其viewController透明。

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

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

编辑

所以做一件事,首先添加一个圆角边框,框架将是你想要的截图UIViewxib

对于圆形边框,您可以使用此category. backgroundColorUIView将是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上面的a,alpha为0.5,背景颜色为黑色。您可以直接从xib. 无需通过代码设置框架。

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

于 2013-10-22T05:23:10.717 回答
7

尝试这个

// create a new view
  UIView *viewPopup=[[UIView alloc]init];
  [viewPopup setBackgroundColor:[UIColor blackColor]];
  viewPopup.alpha=0.6f;

 // add into window
 AppDelegate *appdelgateobj=(AppDelegate *)[[UIApplication sharedApplication]delegate];
 [appdelgateobj.window addSubview:viewPopup];
 [appdelgateobj.window bringSubviewToFront:viewPopup];
于 2013-10-22T05:17:41.503 回答
5

按照以下步骤进行透明视图:

步骤1: 在此处输入图像描述

第2步:

在此处输入图像描述

  • 每当你想要它 Transpertview.hidden=NO 时:
  • 每当你不想要然后 Transpertview.hidden=YES:

可能会有所帮助。

于 2013-10-22T05:31:39.377 回答
1

在您的.m文件中添加#import <QuartzCore/QuartzCore.h>框架并使用以下代码

UIWindow* window = [UIApplication sharedApplication].keyWindow;
    self.dimView = [[UIView alloc] initWithFrame:window.bounds];
    self.dimView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.6];
    self.dimView.userInteractionEnabled = YES;
    [window addSubview:self.dimView];

上面这个是透明的dimView,大小和window差不多。

self.searchTblContainerView = [[UIView alloc] init];
    self.searchTblContainerView.frame = CGRectMake(15, (window.frame.size.height - 300) / 2, 290, 300);
    self.searchTblContainerView.layer.cornerRadius = 15.f;
    self.searchTblContainerView.layer.borderColor = [UIColor blackColor].CGColor; /// set color as per your requirement
    self.searchTblContainerView.layer.borderWidth = 2.f;
    self.searchTblContainerView.alpha = 0.80; /// set as per your requirement 
    self.searchTblContainerView.clipsToBounds = YES;
    [self.dimView addSubview:self.searchTblContainerView];

以上self.searchTblContainerView是包含您的整体的主视图,UIControls例如标签、文本字段、按钮等...并根据您的要求进行设置。

默认设置 hidden 属性,self.dimView.hidden = YES; 并通过alertView (apple)等动画进行显示和隐藏

以下代码用于显示 dimView。

self.searchTblContainerView.transform = CGAffineTransformMakeScale(0.01, 0.01);
        [UIView animateWithDuration:0.30 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            self.searchTblContainerView.transform = CGAffineTransformIdentity;
            self.dimView.hidden = NO;
        } completion:^(BOOL finished){}];

        UIWindow* window = [UIApplication sharedApplication].keyWindow;
        [window bringSubviewToFront:self.dimView];

以下代码用于隐藏 dimView。

 self.searchTblContainerView.transform = CGAffineTransformIdentity;
    [UIView animateWithDuration:0.30 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.searchTblContainerView.transform = CGAffineTransformMakeScale(0.01, 0.01);
    } completion:^(BOOL finished){
        self.dimView.hidden = YES;
    }];

上面的代码是简单的逻辑,可能对您的情况有用。

于 2013-10-22T05:19:33.473 回答