Displacing one view with another with a custom segue animation?

半城伤御伤魂 提交于 2019-12-04 14:39:19

问题


I am trying to implement SUBJ but can't make destination segue appear in my animation. I want to make animation for view change where new segue will displace old one. Currently my perform method looks like this:

- (void) perform {

UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;

[UIView animateWithDuration:2.0
                 animations:^{

                 //tried a lot of staff to make dst view to fall from top at the same time as current view falling to bottom but failed. 

                 src.view.transform=CGAffineTransformMakeTranslation(0, 480);
                 }
                 completion:^(BOOL finished){ 
                     [[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO];
                 }
    ];
}

Any ideas how can I add to my animation block new view appearing from top?

Many thanks!

EDIT:

- (void) perform {

    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    src.view.transform = CGAffineTransformMakeTranslation(0, 0);
    dst.view.transform = CGAffineTransformMakeTranslation(0, -480);

    [UIView animateWithDuration:2.0
                 animations:^{
                         [src.view addSubview:dst.view];
                         src.view.transform = CGAffineTransformMakeTranslation(0, 460);

                     }
                     completion:^(BOOL finished){ 
                         [src presentModalViewController:dst animated:NO];
                     }
     ];

}

Thats how I did it in the end.


回答1:


I don't quite get what you mean by new and old so i assume new = dst and old = src.

- (void) perform {

   UIViewController *src = (UIViewController *) self.sourceViewController;
   UIViewController *dst = (UIViewController *) self.destinationViewController;

   src.view.transform = CGAffineTransformMakeTranslation(0, 0);
   dst.view.transform = CGAffineTransformMakeTranslation(0, -480);

   [UIView animateWithDuration:2.0
                 animations:^{
                     [src presentModalViewController:dst animated:NO];
                     src.view.transform = CGAffineTransformMakeTranslation(0, 480);
                     dst.view.transform = CGAffineTransformMakeTranslation(0, 0);
                 }
   ];
}

This should do it.



来源:https://stackoverflow.com/questions/10034593/displacing-one-view-with-another-with-a-custom-segue-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!