0

I have added a UIView to my [UIApplication sharedApplication].keyWindow and it is working properly.

When a button on the UIView is tapped, I want to push a new UIViewController onto the underlying NavigationController

This all works, but how can I make the UIView animate off the screen, to the left, with the underlying UIViewController ?

Chris
  • 5,485
  • 15
  • 68
  • 130
  • If you want it to animate with a view controller, why not add it as a subview of that view controller's view? – beyowulf Feb 26 '16 at 20:56
  • The `UIView` is added to the `KeyWindow` because the designer wants it to appear on top of the navigation bar (taking up the entire screen) – Chris Feb 26 '16 at 21:02
  • are you opening the view in appDelegate? – alfreedom Feb 26 '16 at 21:28
  • I don't know what "(taking up the entire screen)" means? Where above the navigation bar do they want it? Add a screen shot? – beyowulf Feb 26 '16 at 21:57

1 Answers1

0

You can animate your custom view and at the same time pass the control to the mail view controller to push the next view controller onto the navigation controller's stack... Below is the example code which I have simulated. The animation of your custom view should be in sync with the view controllers animation.

- (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.
}
beyowulf
  • 15,101
  • 2
  • 34
  • 40
Achu22
  • 266
  • 2
  • 7
  • I think you must also do [[[UIApplication sharedApplication] keyWindow] bringSubviewToFront:_v]; after adding subview – alfreedom Feb 26 '16 at 23:34