How can I implement a swiping/sliding animation between views?

后端 未结 3 1180
庸人自扰
庸人自扰 2020-11-30 17:47

I have a few views between which I want to swipe in an iOS program. Right now, I\'m swiping between them using a modal style, with a cross dissolve animation. However, I wan

3条回答
  •  长情又很酷
    2020-11-30 18:30

    You could create a CATransition animation. Here's an example of how you can slide a second view (from left) into the screen whilst pushing the current view out:

    UIView *theParentView = [self.view superview];
    
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.3];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
    [theParentView addSubview:yourSecondViewController.view];
    [self.view removeFromSuperview];
    
    [[theParentView layer] addAnimation:animation forKey:@"showSecondViewController"];
    

提交回复
热议问题