iOS伪转场动画

写在艰苦的日子里。git

  • 本人在简书做者BOC提供的思路下来实现一些动画效果。
  • Github源码地址:github.com/JonHory/Tra…github

  • 经过modal进行转场,设置modalTransitionStyleUIModalTransitionStyleCrossDissolve,设置modalPresentationStyleUIModalPresentationOverFullScreenapi

图片放大缩小的效果

外部只须要传入一个外部的UIImageView便可
1.建立一个UIImageView和一个CGRect来保存图片信息和图片frame信息。
使用- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;方法来获取图片的相对位置。
2.视图将要出现时作动画效果app

- (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [UIView animateWithDuration:AnimationTime animations:^{       
        //这里能够自由发挥了
        self.view.backgroundColor = [UIColor greenColor];self.currentIV.frame = CGRectMake(0, 0, 200, 200);   self.currentIV.center = CGPointMake(self.view.center.x, 200);
        } completion:^(BOOL finished) {
        }];
    }复制代码

3.返回的点击事件处理动画

- (void)back{
    [UIView animateWithDuration:AnimationTime animations:^{
        if ([self.type isEqualToString:@"vv"]) {
            self.view.center = CGPointMake(self.view.center.x, self.view.bounds.size.height*1.5);
        }else {
            self.currentIV.frame = self.oldFrame;
            self.view.backgroundColor = [UIColor clearColor];
        }
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];

}复制代码

4.就这样,效果就出来啦spa

Boss直聘动画效果

用的是截屏的方法来实现背景缩小后置的效果
1.在当前UIViewController用一个UIImageView来保存截图code

-(UIImage *)screenImageWithSize:(CGSize )imgSize{
    UIGraphicsBeginImageContext(imgSize);
    CGContextRef context = UIGraphicsGetCurrentContext();

    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate; //获取app的appdelegate,便于取到当前的window用来截屏
    [app.window.layer renderInContext:context];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}复制代码

2.在下一个VC建立一个减方法,在当前VC中使用cdn

[self presentViewController:vc animated:NO completion:nil];

    [UIView animateWithDuration:0.3 animations:^{
    //当前VC下截图的缩小效果
        self.screenshot.bounds = CGRectMake(50, 50, SCREEN.width - 100, SCREEN.height - 100);
    } completion:^(BOOL finished) {
    //这就是减方法 =_= 动画结束时,改变背景块的frame
        [vc changeBigView];
    }];复制代码

3.在下一个VC返回时,当前VC的截图视图移除。blog

[weakSelf.screenshot removeFromSuperview];复制代码

4.这样,BOSS直聘的动画效果就出现了。事件

按以上思路,就能够实现一些简单常见的动画效果^0^

相关文章
相关标签/搜索