将 UIView 添加到 KeyWindow,如何在调用 pushViewController 时将 UIView 动画关闭屏幕?

Add UIView to KeyWindow, How to Animate UIView Off Screen When pushViewController is Called?

我已经在我的 [UIApplication sharedApplication].keyWindow 中添加了一个 UIView,它工作正常。

当点击 UIView 上的按钮时,我想将一个新的 UIViewController 推送到底层 NavigationController

这一切都有效,但是我怎样才能让 UIView 动画离开屏幕,向左,底层 UIViewController

您可以为您的自定义视图设置动画,同时将控件传递给邮件视图控制器,以将下一个视图控制器推送到导航控制器的堆栈上...下面是我模拟的示例代码。您的自定义视图的动画应该与视图控制器的动画同步。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    _v = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0, 0, 50, 30)];
    [btn setTitle:@"Button" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_v addSubview:btn];
    _v.backgroundColor = [UIColor redColor];
    [[[UIApplication sharedApplication] keyWindow] addSubview:_v];

}

- (void)btnClicked:(id)sender {

    NSLog(@"Btn Clicked");

    [UIView animateWithDuration:0.2
                          delay:0.1
                        options: UIViewAnimationOptionCurveEaseOut
                     animations:^
     {
         _v.frame = CGRectMake(-_v.frame.size.width, 

_v.frame.origin.y, _v.frame.size.width, _v.frame.size.height);
         }
                         completion:^(BOOL finished)
         {
         }];
    UIViewController *c = [self.storyboard instantiateViewControllerWithIdentifier:@"TestVC"];
    [self.navigationController pushViewController:c animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}