//
// ViewController.m
// AnimationDemo
//
// Created by HENAN on 16/12/27.
// Copyright © 2016年 LYS. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UIGestureRecognizerDelegate>
@property (nonatomic,strong)CAShapeLayer *shareLayer;
@property (nonatomic,strong)CADisplayLink *displayLink;
@property (nonatomic,assign)CGPoint centerPoint;
@property (nonatomic,strong)UIView *controlView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.centerPoint = CGPointMake(CGRectGetWidth(self.view.frame) / 2.0, CGRectGetHeight(self.view.frame) / 2.0);
self.controlView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
_controlView.center = self.centerPoint;
_controlView.backgroundColor = [UIColor blackColor];
[self.view addSubview:_controlView];
self.shareLayer = [CAShapeLayer layer];
_shareLayer.frame = self.view.bounds;
_shareLayer.path = [self calculatePathWithPoint:self.controlView.center].CGPath;
_shareLayer.fillColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:_shareLayer];
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkEvent)]; [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureEvent:)];
panGesture.delegate = self;
[self.view addGestureRecognizer:panGesture];
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
CGPoint point = [gestureRecognizer locationInView:gestureRecognizer.view];
if (point.y < (CGRectGetHeight(self.view.frame) / 2.0 - 30) || point.y > (CGRectGetHeight(self.view.frame) / 2.0 + 30)) {
return NO;
}else {
return YES;
}
}
- (UIBezierPath *)calculatePathWithPoint:(CGPoint)point {
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, CGRectGetHeight(self.view.frame) / 2.0)];
[path addLineToPoint:CGPointMake(0, CGRectGetHeight(self.view.frame))];
[path addLineToPoint:CGPointMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
[path addLineToPoint:CGPointMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) / 2.0)];
[path addQuadCurveToPoint:CGPointMake(0, CGRectGetHeight(self.view.frame) / 2.0)
controlPoint:point];
return path;
}
- (void)panGestureEvent:(UIPanGestureRecognizer *)panGesture {
CGPoint point = [panGesture locationInView:panGesture.view];
if (panGesture.state == UIGestureRecognizerStateChanged) {
self.controlView.center = point;
} else if (panGesture.state == UIGestureRecognizerStateCancelled ||
panGesture.state == UIGestureRecognizerStateEnded ||
panGesture.state == UIGestureRecognizerStateFailed) {
[UIView animateWithDuration:1.0 delay:0.0 usingSpringWithDamping:0.25f initialSpringVelocity:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.controlView.center = self.centerPoint;
} completion:nil];
}
}
- (void)displayLinkEvent {
self.shareLayer.path = [self calculatePathWithPoint:self.controlView.layer.presentationLayer.position].CGPath;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
iOS 神奇的果冻效果
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- SlidingLayout是一种Android平台的View控件,可以帮助你实现类似微信网页浏览的下拉功能,也可以...
- 前方高能,老司机~ 一.概述 相信用过path app的人都会被其精美的效果给吸引到,作为一名用户,我首先被其吸引...
- FilenameFilter 我们想要列出指定类型的文件时,java为我们提供了FilenameFilter接口。...