【问题标题】:POP-UP UIView "IMDB App" style [closed]POP-UP UIView“IMDB App”样式[关闭]
【发布时间】:2011-02-24 11:19:47
【问题描述】:

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

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

【问题讨论】:

    标签: ios uiview popup window uipopovercontroller


    【解决方案1】:

    你可以很容易地从头开始制作这样的东西。诀窍是让您的弹出视图控制器具有全屏透明层

    从你的主要观点:

    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 的操作。

    【讨论】:

    • 不错的一个!由于我们是从头开始构建的,使用具有 IMDB 的 3d 翻转动画视图有多难?我从来没有做过 3d 动画,甚至不知道从哪里开始。谢谢绕线器。
    • CATransform3DMakeRotation 就是答案。 :-)
    • 谁能详细解释一下这段代码?非常感谢。谢谢!
    • 第一个代码块将在您现有的应用程序中,由按下按钮之类的东西触发。它只是从 NIB 加载视图控制器并显示它。第二块代码在视图控制器实现内部,有两个技巧。首先,您有两个视图,其中一个是半透明的,另一个位于屏幕外。现在,当 viewWillAppear 被自动调用时,它只需要为弹出窗口设置动画。最后,当你完成它时,调用 slideOut 方法来为它设置动画。
    • 知道了。现在看起来很容易:-) 谢谢@Winder!
    猜你喜欢
    • 1970-01-01
    • 2016-10-29
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2023-01-03
    • 2012-10-19
    • 2013-12-31
    • 2016-12-24
    相关资源
    最近更新 更多