ios - 弹出式 UIView "IMDB App"样式

标签 ios uiview popup window uipopovercontroller

<分区>

是否有一种简单的方法来完成这种弹出窗口(就像 UIPopoverController 那样)还是我应该从头开始构建它?

http://dl.dropbox.com/u/1898217/la-foto.jpg

最佳答案

你可以很容易地从头开始制作这样的东西。诀窍是让你的弹出 View Controller 有一个全屏透明层

从您的主视图:

self.popoverController = [[PopoverController alloc]
                                  initWithNibName:@"PopoverViewController" bundle:nil];
self.popoverController.view.frame =
    CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

[self.view addSubview:self.popoverController.view]; // view is the transparent background
[self.popoverController viewWillAppear:NO];

如果你想要过渡效果,现在只需实现 viewWillAppear 即可:

- (void) viewWillAppear:(BOOL)animated {
    self.fadeView.alpha = 1.0f;
    self.view.alpha = 0.0;
    [self slideIn];
}

// Slide in with whatever effects you want your popup to use
- (void) slideIn {
    //set initial location at bottom of view (my popup slid in from the bottom)

    CGRect frame = self.configView.frame;
    frame.origin = CGPointMake(0.0, self.view.bounds.size.height);
    self.configView.frame = frame;
    [self.view addSubview:self.configView];

    //animate to new location, determined by height of the view in the NIB
    [UIView beginAnimations:@"presentWithSuperview" context:nil];
    [UIView setAnimationDuration:0.5];

    self.view.alpha = 1.0; // fade in background

    frame.origin = CGPointMake(0.0, self.view.bounds.size.height -self.configView.bounds.size.height);
    self.configView.frame = frame; // animate in popup

    [UIView commitAnimations];
}

- (void) slideOut {
    [UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];
    [UIView setAnimationDuration:0.5];
    self.view.alpha = 0.0;
    // Set delegate and selector to remove from superview when animation completes
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    // Move this view to bottom of superview (my popup slides back to the bottom when finished)
    CGRect frame = self.configView.frame;
    frame.origin = CGPointMake(0.0, self.view.bounds.size.height);
    self.configView.frame = frame;

    [UIView commitAnimations];
}

// Finally remove the views when you're done animating out.
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
        [self.configView removeFromSuperview];
        [self.view removeFromSuperview];
    }
}

对于奖励积分,您可以将透明背景设为控件,并让它检测触摸以决定弹出窗口何时消失。我使用界面生成器来调用调用 slideOut 的操作。

关于ios - 弹出式 UIView "IMDB App"样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5103917/

上一篇:ios - iOS 中的事件指示器应该阻止用户访问其他 UI 元素,直到它停止动画

下一篇:iphone - NSMutableArray 和内存管理

相关文章:

iphone - 如何向 UITableView 添加页脚?

iOS 以编程方式生成的 View 具有导致与自动布局冲突的隐藏约束

ios - 如何向 UIView 添加触摸事件?

javascript - 使用 Bootstrap 的 Openlayers 3 弹出窗口

javascript - 如何在弹出窗口中制作十字关闭标志

ios - 无法从测试目标中看到 Swift 类

ios - 避免在 Restkit 路由器上进行 uri 编码

javascript - 让回调在 JavaScript 中同步工作

ios - UIImage 显示为 nil

jquery - 在 jquery 中单击链接时打开模式框