How do you present a UIViewController from the top of the screen instead of the bottom?

后端 未结 5 2183
不思量自难忘°
不思量自难忘° 2021-01-03 13:10

I am using a UIViewController and I use presentModalViewController:controllerr animated:YES to present it but I would like if it would slide down from the top of the screen

5条回答
  •  感情败类
    2021-01-03 13:25

    I created a function for pushing the ViewControllers from all 4 directions:

    - (void) slideLayerInDirection:(NSString *)direction andPush:(UIViewController *)dstVC {
      CATransition* transition = [CATransition animation];
      transition.duration = 0.5;
      transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
      transition.type = kCATransitionPush;
      transition.subtype = direction;
      [self.view.layer addAnimation:transition forKey:kCATransition];
      [self pushViewController:dstVC animated:NO];
    }
    

    The header file contains the following:

    #import 
    
    #define direction_left kCATransitionFromLeft
    #define direction_top kCATransitionFromBottom
    #define direction_right kCATransitionFromRight
    #define direction_bottom kCATransitionFromTop
    

提交回复
热议问题