2016-02-26 59 views
0

我已将UIView添加到我的[UIApplication sharedApplication].keyWindow,它工作正常。将UIView添加到KeyWindow,如何将UIView关闭屏幕动画当调用pushViewController时?

当在UIView按钮被窃听,我想一个新的UIViewController推到底层NavigationController

这一切工作,但我怎么可以让UIView动画关闭屏幕,向左,与底层UIViewController

+0

如果你想要它与视图控制器动画,为什么不把它作为该视图控制器的视图的子视图? – beyowulf

+0

'UIView'被添加到'KeyWindow',因为设计师希望它出现在导航栏的顶部(占据整个屏幕) – Chris

+0

你打开appDelegate中的视图吗? – Quetool

回答

0

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

- (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. 
} 
+0

我想你还必须做[[[UIApplication sharedApplication] keyWindow] bringSubviewToFront:_v];添加子视图后 – Quetool