写了一个日历点击的动画效果

点击的效果是这样的

实现代码:

链接: https://pan.baidu.com/s/1kUZKajH 密码: b6ae

这里写图片描述

gif图片像素比较渣—-实际效果要好的多

图片变换的思路—-

没有点击的图片是白色底色==黑色边缘—- 中间有一个汉字
点击的图片是 绿色底色—没有边缘—-中间汉字变成白色
动画效果是一个缩放的过程—–就是先变小再变大—–
如果选中—-就在绿色和白色之间切换

结构:
底下是一个view +上面一个button
button用来做点击事件的响应者—并且给他添加上文字“一”
底下的view做 drawrect的绘图

关键代码—-

//
//  CircleView.m
//  testAnimationLayer
//
//  Created by mac on 16/10/25.
//  Copyright © 2016年 yyb. All rights reserved.
//

#import "CircleView.h"
#define animateWithDuration_times 0.2
#define PI 3.14159265358979323846
@implementation CircleView


- (void)drawRect:(CGRect)rect
{


    //当选中状态就会走添加绿色的方法----
    if(_isSelected)
    {
        [[UIColor colorWithRed:29/255.0 green:154/255.0 blue:72/255.0 alpha:1] setFill];
        UIBezierPath *path = [UIBezierPath bezierPath];
        [path addArcWithCenter:CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2) radius:self.frame.size.height / 4 startAngle:0.0 endAngle:180.0 clockwise:YES];
        [path fill];
    }else{
        CGRect parentViewBounds = self.bounds;

        CGFloat x = CGRectGetWidth(parentViewBounds)/2;

        CGFloat y = CGRectGetHeight(parentViewBounds)/2;

        //一个不透明类型的Quartz 2D绘画环境,相当于一个画布,你可以在上面任意绘画
        CGContextRef context = UIGraphicsGetCurrentContext();

        //画大圆并填充颜
        UIColor*aColor = [UIColor whiteColor];

        CGContextSetFillColorWithColor(context, aColor.CGColor);//填充颜色

        CGContextSetRGBStrokeColor(context,167.0f/255.0f,167.0f/255.0f,167.0f/255.0f,1.0f);//画笔线的颜色

        CGContextSetLineWidth(context, 3.0);//线的宽度
        /**
         *
         *
         *  @param c          上下文
         *  @param x          圆点坐标
         *  @param y          圆点坐标
         *  @param radius     半径
         *  @param startAngle 开始的弧度   1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
         *  @param endAngle   结束的弧度
         *  @param clockwise  0 顺时针  1 逆时针
         */
        CGContextAddArc(context,x,y, self.frame.size.height / 4, 0, 2*PI, 0); //添加一个圆

        CGContextDrawPath(context, kCGPathFillStroke); //绘制路径加填充
    }
    [super drawRect:rect];


}

- (void)setIsSelected:(BOOL)isSelected {

    //第一次显示的时候放大它
    [UIView animateWithDuration:animateWithDuration_times animations:^{
        CGAffineTransform newTransform = CGAffineTransformScale(self.transform, 0.1, 0.1);
        [self setTransform:newTransform];
        self.alpha = 0.1;

    } completion:^(BOOL finished) {

        _isSelected = isSelected;
        [self setNeedsDisplay];
        //第一次显示的时候放大它
        [UIView animateWithDuration:animateWithDuration_times animations:^{
            CGAffineTransform newTransform = CGAffineTransformConcat(self.transform,  CGAffineTransformInvert(self.transform));
            [self setTransform:newTransform];
            self.alpha = 1.0;
        } completion:^(BOOL finished) {

        }];

    }];


}


@end

点击的瞬间—开始做动画—当放大完成的瞬间—变成另外一种样式—重绘DrawRect

注意点:

尝试添加子layer的动画—-会覆盖掉button的文字—–原因我也不知道

参考layer http://www.cnblogs.com/benbenzhu/p/3615516.html

参考渐隐动画【IOS动画】UIView放大缩小背景淡入淡出动画效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CSS3鼠标点击日历效果可以通过CSS3的伪类和动画实现。具体实现步骤如下: 1. 首先,我们需要创建一个日历的HTML结构,包括年份、月份、日期等元素。 2. 接着,我们可以使用CSS3的伪类:hover来实现鼠标悬停效果。例如,当鼠标悬停在某个日期,可以通过:hover来改变该日期的背景颜色、字体颜色等。 3. 我们还可以使用CSS3的动画效果来实现点击日期效果。例如,当用户点击某个日期,可以通过CSS3的动画效果来实现该日期的放大、缩小、旋转等效果。 下面是一个简单的CSS3鼠标点击日历效果的示例代码: HTML代码: ``` <div class="calendar"> <div class="year">2021</div> <div class="month">6</div> <div class="dates"> <div class="date">1</div> <div class="date">2</div> <div class="date">3</div> ... </div> </div> ``` CSS代码: ``` .calendar { width: 300px; height: 300px; background-color: #fff; border: 1px solid #ccc; padding: 10px; } .year { font-size: 24px; font-weight: bold; margin-bottom: 10px; } .month { font-size: 18px; font-weight: bold; margin-bottom: 10px; } .dates { display: flex; flex-wrap: wrap; } .date { width: 30px; height: 30px; background-color: #eee; margin-right: 5px; margin-bottom: 5px; text-align: center; line-height: 30px; cursor: pointer; } .date:hover { background-color: #ccc; color: #fff; } .date:active { animation-name: click; animation-duration: 0.2s; } @keyframes click { from { transform: scale(1); } to { transform: scale(0.8); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值