UIViewController half screen “drawer slide” animation

后端 未结 3 739
余生分开走
余生分开走 2021-02-15 18:57

I am trying to have a UIViewController that appears with a \"slide\" animation from the right. Not like a Push segue, not like the Facebook app. I want the new View

3条回答
  •  时光说笑
    2021-02-15 19:19

    You can try doing it in your source view controller, and changing the frame for your destnation (the x axis) something like:

    - (void) perform {    
        UIViewController *dst = (UIViewController *) self.destinationViewController;
    
        [dst.view setFrame:CGRectMake(160, 0, YOUR_DST_WIDTH, YOUR_DST_HEIGHT)];
    
        //your animation stuff...
    
        [self addChildViewController:dst]; 
        [self.view addSubview:dst.view]; 
        [dst didMoveToParentViewController:self]; 
    }
    

    And that should do it!

    Let me know if it didn't...

    UPDATE!:

    @CaptJak Hey, sorry that didn't work out for you.. I wrote the following code, and it works without any problems here.. I linked it to a button click.. try it and let me know! (PS: I added animations too!).

    ViewController *tlc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
    [tlc.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
    [self addChildViewController:tlc];
    [self.view addSubview:tlc.view];
    [tlc didMoveToParentViewController:self];
    
    [UIView animateWithDuration:0.3 animations:^{
        [tlc.view setFrame:CGRectMake(-160, 0, self.view.frame.size.width, self.view.frame.size.height)];
    }];
    

提交回复
热议问题