国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

視圖收起動(dòng)畫

2019-11-09 16:17:36
字體:
供稿:網(wǎng)友

最近在寫項(xiàng)目集成即時(shí)通訊,音視頻修改成類似QQ中收起的動(dòng)畫效果:

動(dòng)畫代碼比較簡單,效果:

動(dòng)畫View添加到window中為了方便可以不管到什么控制器都可以懸浮展示,

根據(jù)demo大致寫了下代碼:

//

//  ShowContentView.h

#import <UIKit/UIKit.h>

#import <AVFoundation/AVFoundation.h>

@interface ShowContentView :UIView<CAAnimationDelegate>

@PRoperty (nonatomic,strong)UIView *headView;

@property (nonatomic,strong)UIButton *clicBtn;

/** 動(dòng)畫用的layer */

@property (strong,nonatomic)CAShapeLayer *shapeLayer;

@property (nonatomic,strong)UIButton *smallBtn;

@end

//

//  ShowContentView.m

#import "ShowContentView.h"

@implementation ShowContentView

- (instancetype)initWithFrame:(CGRect)frame

{

    if (self = [superinitWithFrame:frame]) {

        UIView *headView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 120,120)];

        headView.center =CGPointMake(self.center.x,130);

        [headView setBackgroundColor:[UIColorredColor]];

        headView.layer.cornerRadius =60;

        headView.clipsToBounds =YES;

        self.clipsToBounds =YES;

        self.headView = headView;

        [selfaddSubview:headView];

        

        UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

        btn.frame =CGRectMake(30, [UIScreenmainScreen].bounds.size.height-80, [UIScreen mainScreen].bounds.size.width - 60, 30);

        [btn setBackgroundColor:[UIColorredColor]];

        [btn setTitle:@"點(diǎn)我"forState:UIControlStateNormal];

        self.clicBtn = btn;

        [btn addTarget:selfaction:@selector(btnclickAction:)forControlEvents:UIControlEventTouchUpInside];

        [selfaddSubview:btn];

    }

    returnself;

}

- (void)btnclickAction:(UIButton *)btn

{

    //開始的圓形

    UIBezierPath *endPath = [UIBezierPathbezierPathWithOvalInRect:self.headView.frame];

    CGSize startSize =CGSizeMake(self.frame.size.width * 0.5, self.frame.size.height-self.headView.center.y);

    CGFloat radius =sqrt(startSize.width*startSize.width+startSize.height*startSize.height);

    CGRect statF =CGRectInset(self.headView.frame, -radius, -radius);

    UIBezierPath *startPath = [UIBezierPathbezierPathWithOvalInRect:statF];

    

    CAShapeLayer *shapLayer = [CAShapeLayerlayer];

    shapLayer.path = endPath.CGPath;

    self.layer.mask = shapLayer;

    self.shapeLayer = shapLayer;

    //動(dòng)畫

    CABasicAnimation *pathAnimation = [CABasicAnimationanimationWithKeyPath:@"path"];

    pathAnimation.fromValue = (id)startPath.CGPath;

    pathAnimation.toValue = (id)endPath.CGPath;

    pathAnimation.duration =0.5;

    pathAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaSEOut];

    pathAnimation.delegate =self;

    pathAnimation.removedOnCompletion =NO;

    pathAnimation.fillMode =kCAFillModeForwards;

    

    [shapLayer addAnimation:pathAnimationforKey:@"shapAnmination"];

}

#pragma mark - CAAnimationDelegate

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag

{

    if ([animisEqual:[self.shapeLayeranimationForKey:@"shapAnmination"]]) {

        CGRect rect =self.frame;

        rect.origin =self.headView.frame.origin;

        self.bounds = rect;

        rect.size =self.headView.frame.size;

        self.frame = rect;

        

        [UIViewanimateWithDuration:1.0animations:^{

            self.center =CGPointMake([UIScreenmainScreen].bounds.size.width - 60, [UIScreenmainScreen].bounds.size.height - 80);

            self.transform =CGAffineTransformMakeScale(0.5,0.5);

            

        } completion:^(BOOL finished) {

            self.smallBtn.frame =self.frame;

            self.smallBtn.layer.cornerRadius = self.smallBtn.bounds.size.width * 0.5;

            self.smallBtn.layer.masksToBounds = YES;

            [self.superviewaddSubview:_smallBtn];

        }];

    } elseif ([anim isEqual:[self.shapeLayeranimationForKey:@"showAnimation"]]) {

        self.layer.mask =nil;

        self.shapeLayer =nil;

    }

}

- (UIButton *)smallBtn

{

    if (!_smallBtn) {

        _smallBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];

        [_smallBtnaddTarget:selfaction:@selector(microClick)forControlEvents:UIControlEventTouchUpInside];

    }

    return_smallBtn;

}

- (void)microClick

{

    [self.smallBtnremoveFromSuperview];

    self.smallBtn =nil;

    

    [UIViewanimateWithDuration:1.0animations:^{

        self.center =self.headView.center;

        self.transform =CGAffineTransformIdentity;

    } completion:^(BOOL finished) {

        self.bounds = [UIScreenmainScreen].bounds;

        self.frame =self.bounds;

        

        CAShapeLayer *shapeLayer =self.shapeLayer;

        

        // 1.獲取動(dòng)畫縮放開始時(shí)的圓形

        UIBezierPath *startPath = [UIBezierPathbezierPathWithOvalInRect:self.headView.frame];

        

        // 2.獲取動(dòng)畫縮放結(jié)束時(shí)的圓形

        CGSize endSize =CGSizeMake(self.frame.size.width * 0.5, self.frame.size.height - self.headView.center.y);

        CGFloat radius =sqrt(endSize.width * endSize.width + endSize.height * endSize.height);

        CGRect endRect =CGRectInset(self.headView.frame, -radius, -radius);

        UIBezierPath *endPath = [UIBezierPathbezierPathWithOvalInRect:endRect];

        

        // 3.創(chuàng)建shapeLayer作為視圖的遮罩

        shapeLayer.path = endPath.CGPath;

        

        // 添加動(dòng)畫

        CABasicAnimation *pathAnimation = [CABasicAnimationanimationWithKeyPath:@"path"];

        pathAnimation.fromValue = (id)startPath.CGPath;

        pathAnimation.toValue = (id)endPath.CGPath;

        pathAnimation.duration =0.5;

        pathAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

        pathAnimation.delegate =self;

        pathAnimation.removedOnCompletion =NO;

        pathAnimation.fillMode =kCAFillModeForwards;

        

        [shapeLayer addAnimation:pathAnimationforKey:@"showAnmination"];

    }];

}

@end

//

//  ViewController.m

//

#import "ViewController.h"

#import "ShowContentView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    [self.viewsetBackgroundColor:[UIColorgreenColor]];

    ShowContentView *showView = [[ShowContentViewalloc]initWithFrame:self.view.frame];

    [showView setBackgroundColor:[UIColorlightGrayColor]];

    [self.viewaddSubview:showView];

}

@end


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 静宁县| 离岛区| 鹿泉市| 德保县| 温州市| 广元市| 辉县市| 丘北县| 新营市| 新昌县| 定远县| 周宁县| 绥化市| 新巴尔虎右旗| 育儿| 高安市| 友谊县| 连南| 屏南县| 黄龙县| 济源市| 营口市| 德阳市| 湖口县| 城口县| 安泽县| 彭山县| 汉阴县| 陇南市| 新乡县| 惠州市| 达孜县| 元江| 绥芬河市| 娄底市| 武隆县| 德清县| 油尖旺区| 石渠县| 仙游县| 巴林左旗|