iOS 弹出界面抖动动画

2019-02-15  本文已影响5人  e40c669177be
QQ20190215-161612-HD.gif

思路:


image.png

其中D点是可动的, 其他点都是固定不变的, 哎. 其他思路感觉看代码就可以了, 还是得增强语言沟通能力, 说不出来, 看代码吧~😂😂😂, 应该很好理解的

//
//  JC_DrawerController.m
//  JUNCHUANG
//
//  Created by WYC on 2019/2/14.
//  Copyright © 2019年 WYC. All rights reserved.
//弹出的抽屉菜单

#import "JC_DrawerController.h"

@interface JC_DrawerController()

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, assign) CGPoint pointD;

@property (nonatomic, strong) CADisplayLink *displayLink;

@property (nonatomic, strong) CAShapeLayer *shapeLayer;

@property (nonatomic, strong) UIView *view2;

@end

@implementation JC_DrawerController

-(void)viewDidLoad{
[super viewDidLoad];

self.view.backgroundColor = [UIColor clearColor];


UIBlurEffect *blurEffect =[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView =[[UIVisualEffectView alloc]initWithEffect:blurEffect];
effectView.frame = CGRectMake(0,
                             0, 170,JC_SCREENHEIGHT);

[self.view addSubview:effectView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
effectView.userInteractionEnabled = YES;

[effectView addGestureRecognizer:tap];

}

-(void)tapAction{
[self dismissViewControllerAnimated:YES completion:nil];
}

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
 [self setAnimation];
}

-(UITableView *)tableView{
if (!_tableView) {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(150, 0, JC_SCREENWIDTH - 150, JC_SCREENHEIGHT) style:(UITableViewStylePlain)];
//        _tableView.backgroundColor = [UIColor orangeColor];
    }
return _tableView;
}


-(void)setAnimation{

self.pointD = CGPointMake(70, JC_SCREENHEIGHT * 0.5);
UIView *view1 = [[UIView alloc] init];
view1.center = self.pointD;
view1.bounds= CGRectMake(0, 0, 10, 10);
view1.backgroundColor = [UIColor clearColor];
[self.view addSubview:view1];
self.view2 = view1;
[UIView animateWithDuration:3.0 delay:0.0 usingSpringWithDamping:0.2 initialSpringVelocity:0.1 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
    self.pointD = CGPointMake(150, JC_SCREENHEIGHT * 0.5);
    view1.center = self.pointD;
    CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkAction)];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    self.displayLink = displayLink;
} completion:^(BOOL finished) {
    [self.displayLink setPaused:YES];
    self.displayLink = nil;
    [self.view addSubview:self.tableView];
}];

}

-(void)displayLinkAction{

  //重要:只在动画运行时访问呈现树中的对象。当动画在进行中,呈现树就包含了图层显示在屏幕上的那一刻的值。该行为与图层树不同,图层树永远只表示最终的目标值。
//访问图层树中对象的presentationLayer属性将返回一个在呈现树中相对应的对象。你可能会通过该对象获取在动画执行过程中的某一时刻的属性值。
CALayer *presentLayer = self.view2.layer.presentationLayer;
NSLog(@"%@",NSStringFromCGPoint(presentLayer.position));

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(150, 0)];
[path addLineToPoint:CGPointMake(JC_SCREENWIDTH, 0)];
[path addLineToPoint:CGPointMake(JC_SCREENWIDTH, JC_SCREENHEIGHT)];
[path addLineToPoint:CGPointMake(150, JC_SCREENHEIGHT)];

[path addQuadCurveToPoint:CGPointMake(150, 0)
             controlPoint:presentLayer.position];

[path closePath];
self.shapeLayer.path = path.CGPath;

}


-(CAShapeLayer *)shapeLayer{
if (!_shapeLayer) {
    _shapeLayer = ({
        CAShapeLayer *shapLayer = [CAShapeLayer layer];
        shapLayer.fillColor = [UIColor magentaColor].CGColor;
        [self.view.layer addSublayer:shapLayer];
        shapLayer;
    });
}
return _shapeLayer;
}




@end
上一篇 下一篇

猜你喜欢

热点阅读