如何使用iOS 7自定义过渡在顶部呈现半模式视图控制器 [英] How to present a half modal view controller over the top with iOS 7 custom transitions

查看:108
本文介绍了如何使用iOS 7自定义过渡在顶部呈现半模式视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在主视图控制器的顶部显示半视图控制器?

How would I go about presenting a "half view" controller over the top of main view controller?

要求:
- 提供第二个视图控制器滑过主视图控制器的顶部。
- 第二个视图控制器应该只显示超过一半的主视图控制器
- 主视图控制器应该在第二个视图控制器后面保持可见(透明背景,下面没有显示黑色)
- 第二个视图控制器应该动画类似于模态垂直封面的动画,或iOS 7自定义转换
- 当第二个视图控制器处于活动状态时,用户仍然可以与主视图控制器上的按钮交互(即第二个视图控制器不覆盖整个主视图控制器)r
- 第二个视图控制器有自己的复杂逻辑(不能是一个简单的视图)
- 故事板,Segues,iOS 7只有
- 仅限iPhone,而不是iPad。

Requirements: - Present a second view controller that slides over the top of main view controller. - Second view controller should only show over half of the main view controller - Main view controller should remain visible behind second view controller (transparent background, not showing black underneath) - Second view controller should animate in with animation similar to modal vertical cover, or iOS 7 custom transition - User can still interact with buttons on main view controller when second view controller is active (i.e. second view controller does not cover the entire main view controller)r - Second view controller has its own complex logic (cannot be a simple view) - Storyboards, Segues, iOS 7 only - iPhone only, not iPad.

我尝试使用模态视图控制器,但这不允许与主视图控制器交互。有人可以提供一个如何使用iOS7自定义转换或其他方法执行此操作的示例。

I have tried with modal view controller, but this does not allow interaction with main view controller. Can someone provide an example of how to do this with iOS7 custom transition or another method.

推荐答案

一种方法是将半模式控制器添加为子视图控制器,并将其视图设置为动画地点。在这个例子中,我在故事板中创建了半模式控制器,其框架的高度是4英寸iPhone屏幕的一半。您可以使用更多动态方法来考虑不同的屏幕尺寸,但这应该可以让您入手。 / p>

One way to do it is to add the "half modal" controller as a child view controller, and animate its view into place. For this example, I created the "half modal" controller in the storyboard with a frame that's half the height of a 4" iPhone screen. You could use more dynamic methods to account for different screen sizes, but this should get you started.

@interface ViewController ()
@property (strong,nonatomic) UIViewController *modal;
@end

@implementation ViewController


- (IBAction)toggleHalfModal:(UIButton *)sender {
    if (self.childViewControllers.count == 0) {
        self.modal = [self.storyboard instantiateViewControllerWithIdentifier:@"HalfModal"];
        [self addChildViewController:self.modal];
        self.modal.view.frame = CGRectMake(0, 568, 320, 284);
        [self.view addSubview:self.modal.view];
        [UIView animateWithDuration:1 animations:^{
            self.modal.view.frame = CGRectMake(0, 284, 320, 284);;
        } completion:^(BOOL finished) {
            [self.modal didMoveToParentViewController:self];
        }];
    }else{
        [UIView animateWithDuration:1 animations:^{
            self.modal.view.frame = CGRectMake(0, 568, 320, 284);
        } completion:^(BOOL finished) {
            [self.modal.view removeFromSuperview];
            [self.modal removeFromParentViewController];
            self.modal = nil;
        }];
    }
}

这篇关于如何使用iOS 7自定义过渡在顶部呈现半模式视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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